SGR 30–37 — Foreground color (8 basic)
Set foreground to one of black/red/green/yellow/blue/magenta/cyan/white.
Byte forms
Every common string-literal form so you can paste-and-search either direction.
\\x1b[
\x1b[31m (red, similarly 30–37)\\033[
\033[31m\\e[
\e[31mESC [
ESC [ 3 1 mhex
1b 5b 33 31 6dDescription
The 8 basic foreground colors: 30 black, 31 red, 32 green, 33 yellow, 34 blue, 35 magenta, 36 cyan, 37 white. SGR 39 resets the foreground to the terminal default without touching the background. The actual rendered RGB is theme-dependent — there is no canonical RGB for 'ANSI red'. To pick a specific RGB, use truecolor (SGR 38;2;…).
Spec citation: ECMA-48 §8.3.117 (SGR parameters 30–37, 39)
Parameters
| 30 | black |
| 31 | red |
| 32 | green |
| 33 | yellow |
| 34 | blue |
| 35 | magenta |
| 36 | cyan |
| 37 | white |
| 39 | default foreground |
Examples
for c in 30 31 32 33 34 35 36 37; do printf "\033[${c}m■\033[0m"; done; echofor c in range(30, 38): print(f'\x1b[{c}m{c}\x1b[0m', end=' ')for c := 30; c <= 37; c++ { fmt.Printf("\x1b[%dm%d\x1b[0m ", c, c) }for (let c = 30; c <= 37; c++) process.stdout.write(`\x1b[${c}m${c}\x1b[0m `)for (int c = 30; c <= 37; c++) printf("\x1b[%dm%d\x1b[0m ", c, c);Terminal support
- xterm
- yes
- Linux console (fbcon)
- yes
- macOS Terminal.app
- yes
- iTerm2
- yes
- Windows Terminal
- yes
- cmd.exe / ConPTY
- yes
- kitty
- yes
- alacritty
- yes
- WezTerm
- yes
- Ghostty
- yes
- GNOME Terminal
- yes
- Konsole
- yes
- tmux
- no
- GNU screen
- no
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | no | no |