← Back to home

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 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

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.