SGR 40–47 — Background color (8 basic)
Set background 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[41m (red bg, 40–47)\\033[
\033[41m\\e[
\e[41mESC [
ESC [ 4 1 mhex
1b 5b 34 31 6dDescription
Background equivalents of 30–37. 40 black, 41 red, 42 green, 43 yellow, 44 blue, 45 magenta, 46 cyan, 47 white. SGR 49 resets the background to the terminal default. Like the foreground, the rendered RGB depends on the terminal color scheme.
Spec citation: ECMA-48 §8.3.117 (SGR parameters 40–47, 49)
Examples
for c in 40 41 42 43 44 45 46 47; do printf "\033[${c}m \033[0m"; done; echofor c in range(40, 48): print(f'\x1b[{c}m \x1b[0m', end='')for c := 40; c <= 47; c++ { fmt.Printf("\x1b[%dm \x1b[0m", c) }for (let c = 40; c <= 47; c++) process.stdout.write(`\x1b[${c}m \x1b[0m`)for (int c = 40; c <= 47; c++) printf("\x1b[%dm \x1b[0m", 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 |