Strovent SystemsSign in
Reference

Colors: 16, 256 and true color

How terminal colors work, what 256-color and true color mean, and how to turn them on.

Terminal color is set with the SGR escape sequence (ESC [ ... m). There are three levels.

16 colors

  • 30 to 37 set the foreground to black, red, green, yellow, blue, magenta, cyan or white.
  • 40 to 47 set the background the same way.
  • 90 to 97 and 100 to 107 set the bright versions.
  • 1 makes text bold, which many terminals also draw in a brighter color.

The exact shades belong to the terminal's theme, so "red" looks different in different apps.

256 colors

ESC [ 38 ; 5 ; n m     foreground color n
ESC [ 48 ; 5 ; n m     background color n
  • 0 to 15 are the 16 basic colors.
  • 16 to 231 are a 6 x 6 x 6 color cube.
  • 232 to 255 are 24 shades of gray.

True color (24-bit)

ESC [ 38 ; 2 ; r ; g ; b m     foreground
ESC [ 48 ; 2 ; r ; g ; b m     background

Programs that use it look for the COLORTERM variable set to truecolor or 24bit. Over SSH the server may not pass that variable on, so set it in the host's profile if a program says it cannot find true color.

Getting color to work

Dark and light themes

Programs choose colors with the background in mind. A dark gray used on a black background can become unreadable on white. Pick a theme that matches the programs you use, or change their color settings.

Spotted a mistake? Email [email protected].