ANSI Color Codes

All ANSI terminal color codes with foreground/background and 256-color palette.

Reference for 3/4-bit, 8-bit and 24-bit ANSI terminal color codes with a rendered preview. Copy SGR foreground and background sequences for the 16-color, 256-color and truecolor palettes.

What is the difference between 16, 256 and truecolor ANSI?

16-color (3/4-bit) uses codes 30-37, 90-97 for foreground; 256-color (8-bit) uses ESC[38;5;n m with n from 0-255; and truecolor (24-bit) uses ESC[38;2;r;g;b m for any sRGB color. Support depends on the terminal.

Color your terminal output

ANSI SGR (Select Graphic Rendition) sequences set text color in the terminal. There are three tiers: the classic 16-color palette, the 256-color (8-bit) cube, and 24-bit truecolor for any RGB value. This tool previews each color and gives you the exact escape sequence to copy, with the ESC byte already inserted.

How it works

For the 16-color set, foreground codes are 30-37 (standard) and 90-97 (bright); background codes are 40-47 and 100-107. The 256-color palette is built from a formula: indices 0-15 are the base colors, 16-231 form a 6x6x6 RGB cube where each channel maps through the levels 0, 95, 135, 175, 215, 255, and 232-255 are a grayscale ramp. The preview reproduces that math so the swatch matches a typical terminal. Truecolor uses ESC[38;2;r;g;bm, embedding the exact red, green and blue bytes you enter.

Tips and notes

  • Foreground uses the 38 selector, background uses 48, both followed by ;5;n for 256-color or ;2;r;g;b for truecolor.
  • Always end colored runs with ESC[0m so the color does not bleed into later output.
  • Bright colors (90-97) are a convenient shortcut for bold-looking text without the 1m bold attribute.
  • If your terminal only supports 256 colors, pick the nearest cube index rather than truecolor.