search

Found

info Overview

Click any cell in the ANSI 256 palette (16 system colors + 216 RGB cube + 24 grayscale) to copy \e[38;5;Nm, \e[48;5;Nm, bash and printf forms with hex.

📘 How to Use

  1. Click a cell in the palette, or type an index 0-255 to pick a color
  2. Check the foreground and background preview bands to confirm the look
  3. Pick the escape sequence form (foreground, background, bash, printf, or reset) that matches your destination

ANSI 256 Color Picker

0-255
System colors (0-15)
RGB cube (16-231 / 6x6x6)
Grayscale ramp (232-255)
Selected color
Idx 196
Hex #ff0000
RGB 255, 0, 0
The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
Foreground escape
\e[38;5;196m
Background escape
\e[48;5;196m
Bash $'...' form
$'\e[38;5;196m'
printf  form
\033[38;5;196m
Reset
\e[0m
Copied!
Article

ANSI 256 Color Picker | xterm-256color Palette on One Screen

A flat picker for every cell in the xterm-256color palette: 16 system colors, the 216-cell 6×6×6 RGB cube, and 24 grayscale steps, all laid out at once. Click a cell or type an index 0-255 and the tool emits the foreground escape \e[38;5;Nm, the background escape \e[48;5;Nm, the bash $'...' form, the printf \033[...] form, and the reset \e[0m — each on its own row with its own copy button, plus hex and RGB shown as info. Built for the moment you are tweaking a Neovim colorscheme, a starship.toml, a tmux status-line, or an oh-my-zsh theme and do not want to bounce between a cheatsheet tab and a 256-color chart PNG.

💡 About this tool

The 256-color numbering is not memorable. Indices 0-15 are the "system" slots that every terminal emulator paints differently. 16-231 is the RGB cube where the index is 16 + r·36 + g·6 + b with each channel in {0,1,2,3,4,5}. 232-255 is a grayscale ramp at 8 + 10·N. The math is straightforward once you have read the xterm changelog, but in practice — when you actually want "slightly darker blue" or "one step duller green" — computing the index by hand is the friction that makes you give up and reach for hex truecolor instead.

This picker spreads all 256 cells across three sections so you can pick by eye. The selected cell gets a #ec1380 outline, and two preview bands show your chosen color: one as foreground text on a dark background, one as a background fill with WCAG-luminance-flipped text on top so you can sanity-check contrast before locking the color into a theme. Type an index and the grid updates; click a cell and the index input snaps to it. The hex, RGB, and four sequence forms all refresh together.

Each output sits in its own card with a copy button. Use $'\e[38;5;Nm' when you are assigning to a bash variable or building a PS1 (bash interprets the ANSI-C quoted form). Use \033[38;5;Nm inside printf format strings or any POSIX sh context. Use the bare \e[38;5;Nm for echo -e and similar. The reset \e[0m is on its own row so you can grab it without scrolling.

🧐 Frequently Asked Questions

Q. Why do indices 0-15 look different on my terminal? Slots 0-15 are the "system" palette that every emulator overrides with its theme. Solarized, Gruvbox, Tokyo Night, and the iTerm2 / Windows Terminal default schemes all paint these slots differently. The picker shows the xterm default, which matches a vanilla xterm-256color setup but not necessarily yours. If you need theme-portable colors, target indices 16-231 (RGB cube) — those slots are fixed.

Q. What is the difference between \e[38;5;Nm and \033[38;5;Nm? Both encode the same escape byte (0x1B). \e is a shell extension recognized by bash's $'...' ANSI-C quoting and by zsh, while \033 (octal) and \x1b (hex) are POSIX-portable forms understood by printf. Pick \e for bash-only scripts, \033 for portable shell, and \x1b for languages with C-like string escapes.

Q. 24-bit truecolor exists. Do I still need 256-color indices? You do when truecolor is unreliable. tmux below 2.2, screen, some ssh hops, and older Cygwin builds strip the 24-bit form and leave the fallback ANSI. If your theme has to render the same on a bare xterm-256color and on a modern alacritty, the 256-color index is the lowest common denominator. truecolor (\e[38;2;R;G;Bm) is for environments where you have already verified COLORTERM=truecolor.

Q. My PS1 looks fine but the cursor jumps to the wrong column. Bash uses byte length to track the prompt width and will count escape sequences as visible unless you wrap them in \[ and \]. Use PS1='\[\e[38;5;82m\]\u@\h\[\e[0m\] ' (note the brackets around the color sequence). zsh has the same problem and uses %{...%}. starship handles this for you, which is part of why it is so popular.

Q. The "background preview" picks black text on dark colors and white text on light ones. How is that decided? It uses WCAG relative luminance with a 0.5 threshold. Cells whose linearized luminance is above 0.5 get black text; the rest get white. It is a quick readability sanity check, not a colorimetric guarantee — your actual terminal will render slightly differently depending on the GPU and the monitor profile.

Q. What happens if I type 300 or -5 in the index input? The picker clamps to [0, 255]. A non-numeric input is silently ignored (the parse fails and no update fires).

📚 Fun Facts

The 256-color extension shipped in xterm patch #115 around 1999, according to Thomas Dickey's release notes. Until then the world had 8 ANSI colors (\e[30m\e[37m) and the "bright" set 90–97. The push for 256 came largely from the emacs and Vim crowd who wanted richer colorschemes than what 16 slots could give; emacs's tty-color-define predates the xterm extension by a couple of years and was the proof of concept that emulators eventually picked up.

The cube levels [0, 95, 135, 175, 215, 255] look weird because they are not equidistant. Equidistant 0–51–102–153–204–255 would map poorly onto perceived brightness in sRGB, so the cube was tuned to give finer resolution in the shadows. The grayscale ramp 232–255, by contrast, is a simple 8 + 10·N, which is why tmux status-lines and dim background highlights cluster around colour234colour240. The spelling colour instead of color in tmux config is commonly explained as a Nicholas Marriott UK quirk; color resolves as an alias for portability, and both spellings still work today.

If you want to dive deeper into the math, the canonical reference is XTerm Control Sequences (Dickey, ongoing) and the xterm.terminfo entry in ncurses-term. Most modern terminal cheatsheets you find online derive their numbers from those two files.