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]10;#RRGGBB\x07 (set fg) \x1b]11;#RRGGBB\x07 (set bg)\033]10;#RRGGBB\007 / \033]11;#RRGGBB\007\e]10;#RRGGBB\a / \e]11;#RRGGBB\aESC ] 10 ; COLOR BEL / ESC ] 11 ; COLOR BEL1b 5d 31 30 3b ... 07 / 1b 5d 31 31 3b ... 07Description
xterm-ctlseqs documents OSC 10 (set / query the terminal's default foreground colour) and OSC 11 (set / query the default background). Byte shape \x1b]<10|11>;<color>\x07 with BEL terminator, or \x1b]<10|11>;<color>\x1b\\ with ST (ESC \) terminator. The colour argument accepts every form xterm parses: #RRGGBB (8-bit per channel hex), #RGB (4-bit shorthand), rgb:RRRR/GGGG/BBBB (16-bit per channel), or X11 colour names like cornflowerblue from the system's rgb.txt. Passing ? as the value (\x1b]10;?\x07) makes the terminal *reply* on stdin with \x1b]10;<current-color>\x07 — the query form, used by vim's 'background' autodetect, tmux's colour introspection, and TUIs that want to render a theme-coherent UI. Reset to factory default with OSC 110 (foreground) / OSC 111 (background).
Portability — xterm, iTerm2, kitty, alacritty, wezterm, gnome-terminal, Konsole, Ghostty, Windows Terminal, ConPTY 1809+ all support set + query. Linux console does NOT (the kernel framebuffer driver doesn't honour OSC colour sets — colour comes from the kernel palette only). Apple Terminal.app is *partial*: it accepts the set form but never replies to the query form, which breaks vim's autodetect on macOS Terminal until the user manually configures set background=dark / light. Terminator choice matters: BEL (\x07) is universally accepted; ST (ESC \ = the two bytes \x1b\x5c) is the C1 form per ECMA-48 but some legacy parsers don't handle the two-byte ST cleanly — when in doubt, use BEL. tmux requires set-option -g allow-passthrough on plus the right terminal-overrides for queries to return through the multiplexer; without that, the inner pane never sees the reply.
The query form is the load-bearing use case. A TUI that calls \x1b]11;?\x07 and parses the reply (\x1b]11;rgb:1e1e/1e1e/2e2e\x07 for a near-black background, for example) can pick a colour scheme that actually contrasts against the user's terminal instead of guessing from TERM or the $COLORFGBG env hack. The set form should be used sparingly — changing the user's background mid-session is jarring, and many users have spent time tuning their theme; OSC 10 / 11 set is appropriate for self-themed full-screen apps (image viewers, presentation tools) that restore the original via OSC 110 / 111 on exit (using atexit / signal handlers for the durable-cleanup pattern). Security note: terminals that accept OSC writes without prompting let log output set the terminal colours, which is mildly annoying but not exploitable on its own — unlike OSC 52 (clipboard, see osc-clipboard) which has real attack surface and is therefore default-off on most modern terminals. Related: osc-title (OSC 0 / 1 / 2 — same OSC shape for window title), osc-hyperlink (OSC 8 — hyperlink encoding using the same OSC framing), sgr-fg-truecolor (SGR 38;2;R;G;B — per-text foreground colour, which OSC 10's default sits underneath).
Spec citation: xterm-ctlseqs (OSC 10 / 11 / 110 / 111)
Examples
printf '\033]11;#1e1e2e\007' # set bg to deep navy\nprintf '\033]11;?\007' # query current bgimport sys; sys.stdout.write('\x1b]10;#cdd6f4\x07')fmt.Print("\x1b]10;#cdd6f4\x07")process.stdout.write('\x1b]10;#cdd6f4\x07')printf("\x1b]10;#cdd6f4\x07");Used in
Real-world tools that emit this sequence — anchors the bytes to commands you've already used.
- vim, neovim `background=` heuristiceditors query OSC 11 `\x1b]11;?\x07` at startup to read the terminal's actual default background, then auto-flip `:set background=light` vs `dark` — solves the classic problem of colour-schemes painting grey-on-grey when the heuristic guesses wrong
- starship, oh-my-posh, powerlevel10k prompt renderingprompts query OSC 10 / 11 to pick a contrasting accent so an italic-grey segment stays legible whether the user is on a dark or light scheme — falls back to a static palette only if the terminal doesn't answer
- alacritty, WezTerm, kitty live colour reloadall three accept runtime OSC 10 / 11 writes — editing `colors.primary.foreground` in a config file and SIGUSR1-reloading triggers an OSC 10 broadcast so every open shell, vim, and tmux pane gets the new default fg without restart
- iTerm2, Windows Terminal scheme switcheriTerm2's profile-switch hotkey and Windows Terminal's `Ctrl+,` colour-scheme picker both emit OSC 10 / 11 to push the new defaults into the active session — running programs see the change immediately via re-querying on FocusGained
- tmux OSC 10 / 11 passthroughtmux forwards OSC 10 / 11 queries from the active pane to the outer terminal and routes the reply back — without this, vim inside tmux can't sniff the outer terminal's true background and its `background=` heuristic always picks dark
Frequently asked
Short answers to the questions developers actually search for this sequence.
- How do I read the terminal's current default foreground / background colour?
- Write the query form:
\x1b]10;?\x07for foreground,\x1b]11;?\x07for background. A supporting terminal answers on stdin with\x1b]10;rgb:RRRR/GGGG/BBBB\x07(16-bit-per-channel colour). You have to read non-blocking with a short timeout because many terminals (older urxvt, Linux console, most multiplexers without passthrough) never reply. Pair with a 50–100msselect()/poll()fallback to a sensible default; never block on the reply. - Why doesn't
\x1b]10;#ff0000\x07survive after my program exits? - It usually does survive — and that's the problem if you didn't intend it. OSC 10 / 11 mutate terminal state for the lifetime of the *terminal*, not your process. To restore on exit, emit the reset pair
\x1b]110\x07(reset fg) and\x1b]111\x07(reset bg) in your cleanup / signal handler. If your terminal truly is forgetting, you're inside a multiplexer (tmux / screen) that intercepts OSC and forwards a session-scoped copy; the inner OSC dies when tmux thinks the session ends.
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
- yes
- GNU screen
- yes
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | no | partial | yes | yes | no | yes | yes | yes | yes | yes | yes | yes | yes |
Related sequences
In the family cookbook
SGR cookbook · 5. OSC palette override — repaint the slot itself