ANSI Escape Code Reference
Last reviewed on April 27, 2026.
The escape sequences that color terminal output. Click any tile to copy the sequence. The preview cell shows roughly how a true-color terminal would render it. Three sections: the 8 base colors plus their bright variants, the full 256-color palette, and the style modifiers (bold, underline, reverse).
Format:
8 base colors (foreground)
The original ANSI palette. Codes 30–37 are foreground colors, with 0 as the reset code.
8 bright colors (foreground)
Codes 90–97. These map to lighter variants of the same hues. Some terminal themes brighten the regular colors and ignore the bright codes; others reserve the bright codes for genuinely lighter shades.
8 base colors (background)
Codes 40–47 for backgrounds. Bright backgrounds are 100–107.
Style modifiers
Codes between 1 and 9 control style. Most modern terminals support bold, dim, underline, and reverse cleanly. Italic and strikethrough are widely but not universally supported.
256-color palette
Use \x1b[38;5;Nm for foreground and \x1b[48;5;Nm for background, where N is 0–255. The first 16 are the base + bright colors above, then there is a 6×6×6 RGB cube (16–231), and finally a 24-step grayscale ramp (232–255).
24-bit "true color"
Modern terminals support 24-bit color via \x1b[38;2;R;G;Bm for foreground and \x1b[48;2;R;G;Bm for background. R, G, B are decimal 0–255. Most terminal emulators released after 2018 support this; some legacy environments (older Windows command prompt, certain CI runners) still cap at 256 colors.
For curated color values that work well in a hacker-aesthetic terminal, see the cyberpunk color palettes page — every HEX value there can drive a 24-bit ANSI sequence after splitting into R, G, B.
Anatomy of an escape sequence
An ANSI color sequence has three parts:
- The CSI introducer: the byte
0x1b(Escape) followed by[. In a string, this is\x1b[in C-style escapes,\033[in Bash, or\e[as a shorthand many shells accept. - Parameters: a list of numbers separated by semicolons, e.g.
1;31for "bold" plus "red foreground." - The terminator
m: tells the terminal that this is an SGR (Select Graphic Rendition) command.
The empty parameter list — \x1b[0m or just \x1b[m — resets all attributes. End every styled run with a reset, or the styling carries into whatever the terminal prints next.
Worked example: a colored shell prompt
A two-color prompt that shows the user in green and the path in cyan, followed by a reset:
PS1='\[\033[32m\]\u\[\033[0m\]@\[\033[36m\]\w\[\033[0m\]\$ '
The \[ and \] markers are Bash-specific — they tell the shell that the bytes between them do not take up screen columns, so word wrapping does not get confused. Outside the prompt, you do not need them.
Common mistakes
- Forgetting to reset. The most common bug: a colored line without a trailing
\x1b[0mbleeds into the next prompt or the next log line. - Embedding escapes in environments that strip them. Many CI logs render the raw bytes literally because the runner removed the terminal driver. Most CI providers have a "use ANSI colors" setting; check it before debugging your code.
- Mixing
\033and\x1bin the same string. Both notations represent the same byte (0x1b), but only one will be interpreted by the surrounding tool. Pick the one your environment recognizes. - Assuming the terminal honors what your terminal honors. User terminals vary widely in palette and style support. Detect with
$TERM,$COLORTERM, ortput colorsbefore emitting 256-color or true-color sequences. - Hardcoding colors that fail at low contrast. Bright yellow on white is unreadable. Test each code on the dark and light themes you actually ship to.
Where this fits with the other tools on the site
For overall palette choices, the cyberpunk color palettes page has the HEX values; convert them to R;G;B for 24-bit ANSI. For the box-drawing characters that pair well with colored output, see the Unicode symbol reference or the box-drawing tool. To wrap a colored prompt around a banner, generate one with the ASCII banner generator and inject the ANSI escapes around it.