Skip to main content

256-color indexed

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Experimental

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
Formal syntax
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​

ParameterDescription
nColor index (0-255)

The 256-color palette is divided into four ranges:

RangeDescription
0-7Standard colors (same as SGR 30-37)
8-15Bright colors (same as SGR 90-97)
16-2316x6x6 color cube (216 colors)
232-255Grayscale 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​

SpecificationSection
XTerm ctlseqs—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✓YesSGR 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.0SGR 38;5;n and 48;5;n
foot✓YesSGR 38;5;n and 48;5;n handled in csi.c:173-180
Ghostty✓v1.0.0
iTerm2✓v20260216-nightly
Kitty✓YesPresent since early versions
Konsole✓YesSGR 38;5;n / 48;5;n / 58;5;n handled in src/Vt102Emulation.cpp:597-605
mintty✓YesSGR 38;5;n and 48;5;n fully implemented at termout.c:2208-2271
mlterm✓rel-3_1_6
PuTTY✓0.58SGR 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✓YesSGR 38;5;n and 48;5;n supported in collect_sgr_color function
WezTerm✓YesImplemented 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✓YesSGR 38;5;n and 48;5;n via SetIndexedForeground256/SetIndexedBackground256
xterm✓YesSGR 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.0Requires COLOR and COLORS256 compile flags
tmux✓0.8SGR 38;5;n and 48;5;n
tuios✓v0.0.15
Zellij✓v0.12.0

See also​