256-color indexed
256-color indexed mode uses SGR 38;5 and 48;5 to set the foreground and background to any of 256 indexed colors.
Syntax
CSI 38;5;n m SGR — Set foreground to indexed color n
CSI 48;5;n m SGR — Set background to indexed color n
SGR-fg-256 = 0x1b, "[", "38", ";", "5", ";", n, "m" ;
SGR-bg-256 = 0x1b, "[", "48", ";", "5", ";", n, "m" ;
n = digit, { digit } ; (* 0-255 *)
digit = "0" | "1" | "2" | "3" | "4"
| "5" | "6" | "7" | "8" | "9" ;Parameters
| Parameter | Description |
|---|---|
n | Color index (0-255) |
The 256-color palette is divided into four ranges:
| Range | Description |
|---|---|
| 0-7 | Standard colors (same as SGR 30-37) |
| 8-15 | Bright colors (same as SGR 90-97) |
| 16-231 | 6x6x6 color cube (216 colors) |
| 232-255 | Grayscale ramp (24 shades) |
Description
The 256-color extension was introduced by XTerm. It uses ECMA-48's reserved SGR parameters 38 and 48 (intended for extended color in ISO 8613-6 / ITU-T T.416) with the sub-parameter 5 to indicate indexed color mode, followed by the color index.
The 6x6x6 color cube (indices 16-231) maps to RGB values using the formula: index = 16 + 36r + 6g + b, where r, g, b are each in the range 0-5.
The grayscale ramp (indices 232-255) provides 24 shades from dark gray to light gray, not including pure black (use index 0) or pure white (use index 15).
Colors 0-15 are typically user-configurable and match the standard/bright ANSI colors. Colors 16-255 have fixed RGB values in most terminals.
Examples
printf '\e[38;5;196mBright red (index 196)\e[0m\n'
printf '\e[48;5;21mBlue background (index 21)\e[0m\n'
printf '\e[38;5;245mGray text (index 245)\e[0m\n'
Specifications
| Specification | Section |
|---|---|
| XTerm ctlseqs | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✓ | Yes | SGR 38;5;n / 48;5;n - parameter 38/48 supported per docs |
| Bobcat | ? | ? | Implemented in external TerminalCtrl library, not in Bobcat source code |
| contour | ✓ | v0.1.0 | SGR 38;5;n and 48;5;n |
| foot | ✓ | Yes | SGR 38;5;n and 48;5;n handled in csi.c:173-180 |
| Ghostty | ✓ | v1.0.0 | |
| iTerm2 | ✓ | v20260216-nightly | |
| Kitty | ✓ | Yes | Present since early versions |
| Konsole | ✓ | Yes | SGR 38;5;n / 48;5;n / 58;5;n handled in src/Vt102Emulation.cpp:597-605 |
| mintty | ✓ | Yes | SGR 38;5;n and 48;5;n fully implemented at termout.c:2208-2271 |
| mlterm | ✓ | rel-3_1_6 | |
| PuTTY | ✓ | 0.58 | SGR 38;5;n and 48;5;n implemented in commit e4e10e49 |
| Rio | ✓ | v0.0.3 | |
| rxvt-unicode | ✓ | rxvt-unicode-9.09 | |
| st | ✓ | 0.5 | |
| terminology | ✓ | v0.1.0 | |
| VT100 | ✗ | No | |
| VTE | ✓ | Yes | SGR 38;5;n and 48;5;n supported in collect_sgr_color function |
| WezTerm | ✓ | Yes | Implemented via SGR 38;5;n / 48;5;n with both semicolon and colon separators - see wezterm-escape-parser/src/csi.rs:2552-2567 |
| Windows Terminal | ✓ | Yes | SGR 38;5;n and 48;5;n via SetIndexedForeground256/SetIndexedBackground256 |
| xterm | ✓ | Yes | SGR 38;5;n / 48;5;n supported when compiled with 256-color support |
| xterm.js | ✓ | 3.13.0 | |
| Multiplexers | |||
| cy | ✓ | Yes | |
| GNU Screen | ✓ | v.4.2.0 | Requires COLOR and COLORS256 compile flags |
| tmux | ✓ | 0.8 | SGR 38;5;n and 48;5;n |
| tuios | ✓ | v0.0.15 | |
| Zellij | ✓ | v0.12.0 | |
See also
- Standard ANSI colors — 8+8 basic colors
- 24-bit truecolor (semicolons) — Full RGB color