OSC 17 — Set highlight (selection) background colour
Change the background colour the terminal paints behind selected (highlighted) text.
Byte forms
Every common string-literal form so you can paste-and-search either direction.
\x1b]17;#RRGGBB\x07 (set) \x1b]17;?\x07 (query)\033]17;#RRGGBB\007\e]17;#RRGGBB\aESC ] 17 ; COLOR BEL1b 5d 31 37 3b ... 07Description
OSC 17 sets the background colour used for selected (mouse-highlighted) text in the terminal — the band of colour you see behind a click-drag selection. Colour syntax matches OSC 10 / 11 / 12: `#RRGGBB`, `#RGB`, `rgb:RRRR/GGGG/BBBB`, X11 names. Sending `?` queries the current value (the terminal replies with `\x1b]17;rgb:...\x07`). Historically xterm-specific (paired with OSC 19 for highlight fg); most modern terminals expose selection colour only through their config file or theme engine and ignore the runtime OSC. Use the matching reset `\x1b]117\x07` to restore the user's configured highlight bg. Note: the foreground partner is OSC 19, not OSC 18 — OSC 18 is reserved for the Tek-emulator cursor colour and obsolete.
Spec citation: xterm-ctlseqs (OSC 17 / 117)
Examples
printf '\033]17;#45475a\007' # set selection bg\nprintf '\033]17;?\007' # queryimport sys; sys.stdout.write('\x1b]17;#45475a\x07')fmt.Print("\x1b]17;#45475a\x07")process.stdout.write('\x1b]17;#45475a\x07')printf("\x1b]17;#45475a\x07");Terminal support
- xterm
- yes
- Linux console (fbcon)
- no
- macOS Terminal.app
- no
- iTerm2
- no
- Windows Terminal
- no
- cmd.exe / ConPTY
- no
- kitty
- no
- alacritty
- no
- WezTerm
- partial
- Ghostty
- no
- GNOME Terminal
- partial
- Konsole
- partial
- 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 | no | no | no | no | no | no | no | partial | no | partial | partial | no | no |