Skip to main content
ansicode

SGR 48;5;n — 256-color background

Pick a background color from the 256-color xterm palette.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[48;5;Nm
\\033[\033[48;5;Nm
\\e[\e[48;5;Nm
ESC [ESC [ 4 8 ; 5 ; N m
hex1b 5b 34 38 3b 35 3b <N> 6d

Description

Background sibling of `\x1b[38;5;Nm`. N is 0–255 with the same palette layout: 0–7 basic, 8–15 bright, 16–231 a 6×6×6 RGB cube (`16 + 36*r + 6*g + b`), 232–255 a 24-step grayscale ramp. The colon sub-parameter form `\x1b[48:5:Nm` is also accepted by ECMA-48-strict parsers. Reset just the background with `\x1b[49m`.

Spec citation: xterm-ctlseqs (256-color extension)

Examples

bash
printf '\033[48;5;202m highlight \033[49m\n'
python
print('\x1b[48;5;202m highlight \x1b[0m')
go
fmt.Print("\x1b[48;5;202m highlight \x1b[0m")
javascript
console.log('\x1b[48;5;202m highlight \x1b[0m')
c
printf("\x1b[48;5;202m highlight \x1b[0m\n");

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
yes
iTerm2
yes
Windows Terminal
yes
cmd.exe / ConPTY
partial
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
yes
Konsole
yes
tmux
no
GNU screen
no

Related sequences

In the family cookbook

SGR cookbook · 3. 256-color indexed — `\x1b[38;5;n m`