xterm.codes Developer Reference

ANSI Escape Codes

A quick reference for 3-bit, 4-bit, 8-bit (256-color), and 24-bit (Truecolor) terminal styling.

Escape Syntax:
256-Color Mode:
Active Format: \x1b[38;5;Nm (Hex Foreground)

1. Syntax & Anatomy

escape sequence structure

ANSI escape sequences control text formatting, colors, and cursor positioning in Unix and terminal environments. Every sequence begins with an Escape character followed by a Control Sequence Introducer (CSI), zero or more parameter codes separated by semicolons, and a terminating character.

Representation Example Sequence Environment / Language
Hexadecimal (\x1b) \x1b[31m C, C++, Python, JavaScript/Node.js, Rust
Octal (\033) \033[31m POSIX Shell, C, Perl, Ruby, Awk
Escape shorthand (\e) \e[31m Bash, Zsh, GNU echo -e, GNU printf
ASCII Control (ESC) ^[ [ 31m Raw terminal input (Ctrl+[ or ASCII 27)

Select Graphic Rendition (SGR): Color and styling sequences always terminate with m. Parameters can be combined into a single sequence with semicolons:

SGR chaining & reset

# Format: <esc>[<attribute>;<foreground>;<background>m

\x1b[1;31;40mBold Red on Black\x1b[0m → Bold (1) + Red Text (31) + Black BG (40)

Δ Tip: Click any code token, table cell, or swatch on this page to copy its escape sequence to your clipboard.

2. Text Attributes

styles & weights
Code Effect Reset Code Notes / Support
\x1b[0m Reset / Normal — Turns off all styles, colors, and backgrounds
\x1b[1m Bold / High Intensity \x1b[22m Increases font weight; often renders colors brighter
\x1b[2m Dim / Faint \x1b[22m Decreases color intensity and luminosity
\x1b[3m Italic \x1b[23m Slanted/italic typeface (widely supported in modern terminals)
\x1b[4m Underline \x1b[24m Standard single underline beneath text
\x1b[5m Slow Blink \x1b[25m Less than 150 blinks/min (disabled or replaced with bold in many terminals)
\x1b[7m Inverse / Reverse \x1b[27m Swaps foreground and background color
\x1b[8m Conceal / Hidden \x1b[28m Hides characters (often used for password inputs)
\x1b[9m Strikethrough \x1b[29m Draws a horizontal line through text

3. Standard 16 Colors

3-bit & 4-bit palette

The foundation of terminal color output. Standard colors (codes 30–37 FG, 40–47 BG) and high-intensity bright variants (codes 90–97 FG, 100–107 BG). Values update with your selected syntax above.

Color Standard FG Standard BG Standard Preview Bright FG Bright BG Bright Preview
Black \x1b[30m \x1b[40m Black \x1b[90m \x1b[100m Bright Black
Red \x1b[31m \x1b[41m Red \x1b[91m \x1b[101m Bright Red
Green \x1b[32m \x1b[42m Green \x1b[92m \x1b[102m Bright Green
Yellow \x1b[33m \x1b[43m Yellow \x1b[93m \x1b[103m Bright Yellow
Blue \x1b[34m \x1b[44m Blue \x1b[94m \x1b[104m Bright Blue
Magenta \x1b[35m \x1b[45m Magenta \x1b[95m \x1b[105m Bright Magenta
Cyan \x1b[36m \x1b[46m Cyan \x1b[96m \x1b[106m Bright Cyan
White \x1b[37m \x1b[47m White \x1b[97m \x1b[107m Bright White
Default / Reset \x1b[39m \x1b[49m Resets foreground or background back to default terminal color

4. 256-Color Palette (8-Bit)

xterm color lookup

Extended 8-bit palette. Every swatch displays its value directly for easy copying—click any cell to copy instantly, or double-click to select.

Escape Syntax:
256-Color Mode:
Active Format: \x1b[38;5;Nm (Hex Foreground)

System Colors (Codes 0–15)

0–7 Standard • 8–15 High-Intensity
\x1b[38;5;0mBlack
\x1b[38;5;1mMaroon
\x1b[38;5;2mGreen
\x1b[38;5;3mOlive
\x1b[38;5;4mNavy
\x1b[38;5;5mPurple
\x1b[38;5;6mTeal
\x1b[38;5;7mSilver
\x1b[38;5;8mGrey
\x1b[38;5;9mRed
\x1b[38;5;10mLime
\x1b[38;5;11mYellow
\x1b[38;5;12mBlue
\x1b[38;5;13mFuchsia
\x1b[38;5;14mAqua
\x1b[38;5;15mWhite

6×6×6 RGB Cube (Codes 16–231)

216 colors

Index formula: 16 + (36 × R) + (6 × G) + B where R, G, B ∈ [0, 5]. Channel values: 0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff.

Slice R = 0 (0x00) Codes 16 – 51
\x1b[38;5;16mGrey0
\x1b[38;5;17mNavyBlue
\x1b[38;5;18mDarkBlue
\x1b[38;5;19mBlue3
\x1b[38;5;20mBlue3
\x1b[38;5;21mBlue1
\x1b[38;5;22mDarkGreen
\x1b[38;5;23mDeepSkyBlue4
\x1b[38;5;24mDeepSkyBlue4
\x1b[38;5;25mDeepSkyBlue4
\x1b[38;5;26mDodgerBlue3
\x1b[38;5;27mDodgerBlue2
\x1b[38;5;28mGreen4
\x1b[38;5;29mSpringGreen4
\x1b[38;5;30mTurquoise4
\x1b[38;5;31mDeepSkyBlue3
\x1b[38;5;32mDeepSkyBlue3
\x1b[38;5;33mDodgerBlue1
\x1b[38;5;34mGreen3
\x1b[38;5;35mSpringGreen3
\x1b[38;5;36mDarkCyan
\x1b[38;5;37mLightSeaGreen
\x1b[38;5;38mDeepSkyBlue2
\x1b[38;5;39mDeepSkyBlue1
\x1b[38;5;40mGreen3
\x1b[38;5;41mSpringGreen3
\x1b[38;5;42mSpringGreen2
\x1b[38;5;43mCyan3
\x1b[38;5;44mDarkTurquoise
\x1b[38;5;45mTurquoise2
\x1b[38;5;46mGreen1
\x1b[38;5;47mSpringGreen2
\x1b[38;5;48mSpringGreen1
\x1b[38;5;49mMediumSpringGreen
\x1b[38;5;50mCyan2
\x1b[38;5;51mCyan1
↓ Green: rows 0 to 5 Blue: cols 0 to 5 →
Slice R = 1 (0x5f) Codes 52 – 87
\x1b[38;5;52mDarkRed
\x1b[38;5;53mDeepPink4
\x1b[38;5;54mPurple4
\x1b[38;5;55mPurple4
\x1b[38;5;56mPurple3
\x1b[38;5;57mBlueViolet
\x1b[38;5;58mOrange4
\x1b[38;5;59mGrey37
\x1b[38;5;60mMediumPurple4
\x1b[38;5;61mSlateBlue3
\x1b[38;5;62mSlateBlue3
\x1b[38;5;63mRoyalBlue1
\x1b[38;5;64mChartreuse4
\x1b[38;5;65mDarkSeaGreen4
\x1b[38;5;66mPaleTurquoise4
\x1b[38;5;67mSteelBlue
\x1b[38;5;68mSteelBlue3
\x1b[38;5;69mCornflowerBlue
\x1b[38;5;70mChartreuse3
\x1b[38;5;71mDarkSeaGreen4
\x1b[38;5;72mCadetBlue
\x1b[38;5;73mCadetBlue
\x1b[38;5;74mSkyBlue3
\x1b[38;5;75mSteelBlue1
\x1b[38;5;76mChartreuse3
\x1b[38;5;77mPaleGreen3
\x1b[38;5;78mSeaGreen3
\x1b[38;5;79mAquamarine3
\x1b[38;5;80mMediumTurquoise
\x1b[38;5;81mSteelBlue1
\x1b[38;5;82mChartreuse2
\x1b[38;5;83mSeaGreen2
\x1b[38;5;84mSeaGreen1
\x1b[38;5;85mSeaGreen1
\x1b[38;5;86mAquamarine1
\x1b[38;5;87mDarkSlateGray2
↓ Green: rows 0 to 5 Blue: cols 0 to 5 →
Slice R = 2 (0x87) Codes 88 – 123
\x1b[38;5;88mDarkRed
\x1b[38;5;89mDeepPink4
\x1b[38;5;90mDarkMagenta
\x1b[38;5;91mDarkMagenta
\x1b[38;5;92mDarkViolet
\x1b[38;5;93mPurple
\x1b[38;5;94mOrange4
\x1b[38;5;95mLightPink4
\x1b[38;5;96mPlum4
\x1b[38;5;97mMediumPurple3
\x1b[38;5;98mMediumPurple3
\x1b[38;5;99mSlateBlue1
\x1b[38;5;100mYellow4
\x1b[38;5;101mWheat4
\x1b[38;5;102mGrey53
\x1b[38;5;103mLightSlateGrey
\x1b[38;5;104mMediumPurple
\x1b[38;5;105mLightSlateBlue
\x1b[38;5;106mYellow4
\x1b[38;5;107mDarkOliveGreen3
\x1b[38;5;108mDarkSeaGreen
\x1b[38;5;109mLightSkyBlue3
\x1b[38;5;110mLightSkyBlue3
\x1b[38;5;111mSkyBlue2
\x1b[38;5;112mChartreuse2
\x1b[38;5;113mDarkOliveGreen3
\x1b[38;5;114mPaleGreen3
\x1b[38;5;115mDarkSeaGreen3
\x1b[38;5;116mDarkSlateGray3
\x1b[38;5;117mSkyBlue1
\x1b[38;5;118mChartreuse1
\x1b[38;5;119mLightGreen
\x1b[38;5;120mLightGreen
\x1b[38;5;121mPaleGreen1
\x1b[38;5;122mAquamarine1
\x1b[38;5;123mDarkSlateGray1
↓ Green: rows 0 to 5 Blue: cols 0 to 5 →
Slice R = 3 (0xaf) Codes 124 – 159
\x1b[38;5;124mRed3
\x1b[38;5;125mDeepPink4
\x1b[38;5;126mMediumVioletRed
\x1b[38;5;127mMagenta3
\x1b[38;5;128mDarkViolet
\x1b[38;5;129mPurple
\x1b[38;5;130mDarkOrange3
\x1b[38;5;131mIndianRed
\x1b[38;5;132mHotPink3
\x1b[38;5;133mMediumOrchid3
\x1b[38;5;134mMediumOrchid
\x1b[38;5;135mMediumPurple2
\x1b[38;5;136mDarkGoldenrod
\x1b[38;5;137mLightSalmon3
\x1b[38;5;138mRosyBrown
\x1b[38;5;139mGrey63
\x1b[38;5;140mMediumPurple2
\x1b[38;5;141mMediumPurple1
\x1b[38;5;142mGold3
\x1b[38;5;143mDarkKhaki
\x1b[38;5;144mNavajoWhite3
\x1b[38;5;145mGrey69
\x1b[38;5;146mLightSteelBlue3
\x1b[38;5;147mLightSteelBlue
\x1b[38;5;148mYellow3
\x1b[38;5;149mDarkOliveGreen3
\x1b[38;5;150mDarkSeaGreen3
\x1b[38;5;151mDarkSeaGreen2
\x1b[38;5;152mLightCyan3
\x1b[38;5;153mLightSkyBlue1
\x1b[38;5;154mGreenYellow
\x1b[38;5;155mDarkOliveGreen2
\x1b[38;5;156mPaleGreen1
\x1b[38;5;157mDarkSeaGreen2
\x1b[38;5;158mDarkSeaGreen1
\x1b[38;5;159mPaleTurquoise1
↓ Green: rows 0 to 5 Blue: cols 0 to 5 →
Slice R = 4 (0xd7) Codes 160 – 195
\x1b[38;5;160mRed3
\x1b[38;5;161mDeepPink3
\x1b[38;5;162mDeepPink3
\x1b[38;5;163mMagenta3
\x1b[38;5;164mMagenta3
\x1b[38;5;165mMagenta2
\x1b[38;5;166mDarkOrange3
\x1b[38;5;167mIndianRed
\x1b[38;5;168mHotPink3
\x1b[38;5;169mHotPink2
\x1b[38;5;170mOrchid
\x1b[38;5;171mMediumOrchid1
\x1b[38;5;172mOrange3
\x1b[38;5;173mLightSalmon3
\x1b[38;5;174mLightPink3
\x1b[38;5;175mPink3
\x1b[38;5;176mPlum3
\x1b[38;5;177mViolet
\x1b[38;5;178mGold3
\x1b[38;5;179mLightGoldenrod3
\x1b[38;5;180mTan
\x1b[38;5;181mMistyRose3
\x1b[38;5;182mThistle3
\x1b[38;5;183mPlum2
\x1b[38;5;184mYellow3
\x1b[38;5;185mKhaki3
\x1b[38;5;186mLightGoldenrod2
\x1b[38;5;187mLightYellow3
\x1b[38;5;188mGrey84
\x1b[38;5;189mLightSteelBlue1
\x1b[38;5;190mYellow2
\x1b[38;5;191mDarkOliveGreen1
\x1b[38;5;192mDarkOliveGreen1
\x1b[38;5;193mDarkSeaGreen1
\x1b[38;5;194mHoneydew2
\x1b[38;5;195mLightCyan1
↓ Green: rows 0 to 5 Blue: cols 0 to 5 →
Slice R = 5 (0xff) Codes 196 – 231
\x1b[38;5;196mRed1
\x1b[38;5;197mDeepPink2
\x1b[38;5;198mDeepPink1
\x1b[38;5;199mDeepPink1
\x1b[38;5;200mMagenta2
\x1b[38;5;201mMagenta1
\x1b[38;5;202mOrangeRed1
\x1b[38;5;203mIndianRed1
\x1b[38;5;204mIndianRed1
\x1b[38;5;205mHotPink
\x1b[38;5;206mHotPink
\x1b[38;5;207mMediumOrchid1
\x1b[38;5;208mDarkOrange
\x1b[38;5;209mSalmon1
\x1b[38;5;210mLightCoral
\x1b[38;5;211mPaleVioletRed1
\x1b[38;5;212mOrchid2
\x1b[38;5;213mOrchid1
\x1b[38;5;214mOrange1
\x1b[38;5;215mSandyBrown
\x1b[38;5;216mLightSalmon1
\x1b[38;5;217mLightPink1
\x1b[38;5;218mPink1
\x1b[38;5;219mPlum1
\x1b[38;5;220mGold1
\x1b[38;5;221mLightGoldenrod2
\x1b[38;5;222mLightGoldenrod2
\x1b[38;5;223mNavajoWhite1
\x1b[38;5;224mMistyRose1
\x1b[38;5;225mThistle1
\x1b[38;5;226mYellow1
\x1b[38;5;227mLightGoldenrod1
\x1b[38;5;228mKhaki1
\x1b[38;5;229mWheat1
\x1b[38;5;230mCornsilk1
\x1b[38;5;231mGrey100
↓ Green: rows 0 to 5 Blue: cols 0 to 5 →

Grayscale Ramp (Codes 232–255)

24 shades

Formula: gray = 8 + (10 × (n - 232)) for values from 8 (#080808) to 238 (#eeeeee).

\x1b[38;5;232mGrey3
\x1b[38;5;233mGrey7
\x1b[38;5;234mGrey11
\x1b[38;5;235mGrey15
\x1b[38;5;236mGrey19
\x1b[38;5;237mGrey23
\x1b[38;5;238mGrey27
\x1b[38;5;239mGrey30
\x1b[38;5;240mGrey35
\x1b[38;5;241mGrey39
\x1b[38;5;242mGrey42
\x1b[38;5;243mGrey46
\x1b[38;5;244mGrey50
\x1b[38;5;245mGrey54
\x1b[38;5;246mGrey58
\x1b[38;5;247mGrey62
\x1b[38;5;248mGrey66
\x1b[38;5;249mGrey70
\x1b[38;5;250mGrey74
\x1b[38;5;251mGrey78
\x1b[38;5;252mGrey82
\x1b[38;5;253mGrey85
\x1b[38;5;254mGrey89
\x1b[38;5;255mGrey93

5. 24-Bit Truecolor (RGB)

16.7 million colors

Allows direct specification of 24-bit RGB values from 0 to 255. Supported by almost all modern terminal emulators (tmux, Alacritty, Kitty, iTerm2, macOS Terminal, Windows Terminal, xterm).

Target Sequence Format Example (Orange: 255, 128, 0)
Foreground <esc>[38;2;<r>;<g>;<b>m \x1b[38;2;255;128;0m
Background <esc>[48;2;<r>;<g>;<b>m \x1b[48;2;20;30;45m
Combined <esc>[38;2;r;g;b;48;2;r;g;bm \x1b[38;2;255;255;255;48;2;255;128;0m

6. Terminal Controls

cursor & screen sequences
Sequence Action Description
\x1b[0m Reset All Reset all attributes, foreground, and background colors
\x1b[2J Clear Screen Clears the entire visible screen
\x1b[H Cursor Home Moves cursor to row 1, column 1 (upper-left corner)
\x1b[<r>;<c>H Move Cursor Moves cursor to specific 1-indexed row <r> and column <c>
\x1b[<n>A Cursor Up Moves cursor up by <n> rows
\x1b[<n>B Cursor Down Moves cursor down by <n> rows
\x1b[<n>C Cursor Forward Moves cursor forward (right) by <n> columns
\x1b[<n>D Cursor Back Moves cursor backward (left) by <n> columns
\x1b[2K Clear Line Clears the entire current line
\x1b[0K Clear to Line End Clears from cursor position to the end of the line
\x1b[?25l Hide Cursor Hides terminal cursor (useful in TUI applications)
\x1b[?25h Show Cursor Restores terminal cursor visibility
\x1b[s Save Cursor Saves current cursor coordinates
\x1b[u Restore Cursor Restores previously saved cursor coordinates

7. Practical Code Snippets

interactive terminal examples
# Portable POSIX printf (uses octal \033)
printf "\033[1;32m✓ Success:\033[0m All test suites passed.\n"
printf "\033[1;31m✗ Error:\033[0m Verification failed at step 4.\n"

# 256-color foreground (color 208 = orange)
printf "\033[38;5;208mNotice: Cache rebuilt in 45ms\033[0m\n"

# 24-bit Truecolor (RGB: 255, 120, 0)
printf "\033[38;2;255;120;0mCustom RGB orange text\033[0m\n"