Skip to main content
ansicode

OSC 10 / 11 — Set default foreground / background color

Set the terminal's default foreground (OSC 10) or background (OSC 11) color, or query the current value.

Byte forms

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

\\x1b[\x1b]10;#RRGGBB\x07 (set fg) \x1b]11;#RRGGBB\x07 (set bg)
\\033[\033]10;#RRGGBB\007 / \033]11;#RRGGBB\007
\\e[\e]10;#RRGGBB\a / \e]11;#RRGGBB\a
ESC [ESC ] 10 ; COLOR BEL / ESC ] 11 ; COLOR BEL
hex1b 5d 31 30 3b ... 07 / 1b 5d 31 31 3b ... 07

Description

OSC 10 sets the terminal's default foreground color, OSC 11 the background. The color argument accepts the same forms xterm parses: `#RRGGBB`, `#RGB`, `rgb:RRRR/GGGG/BBBB`, or X11 names like `cornflowerblue`. Passing `?` as the value (`\x1b]10;?\x07`) makes the terminal reply with the current color in the same syntax — used by tools like vim's `'background'` autodetect to choose a light or dark colorscheme. Reset to the terminal default with OSC 110 (fg) / OSC 111 (bg).

Spec citation: xterm-ctlseqs (OSC 10 / 11 / 110 / 111)

Examples

bash
printf '\033]11;#1e1e2e\007'   # set bg to deep navy\nprintf '\033]11;?\007'        # query current bg
python
import sys; sys.stdout.write('\x1b]10;#cdd6f4\x07')
go
fmt.Print("\x1b]10;#cdd6f4\x07")
javascript
process.stdout.write('\x1b]10;#cdd6f4\x07')
c
printf("\x1b]10;#cdd6f4\x07");

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
partial
iTerm2
yes
Windows Terminal
yes
cmd.exe / ConPTY
no
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 · 5. OSC palette override — repaint the slot itself