Skip to main content
ansicode

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[\x1b]17;#RRGGBB\x07 (set) \x1b]17;?\x07 (query)
\\033[\033]17;#RRGGBB\007
\\e[\e]17;#RRGGBB\a
ESC [ESC ] 17 ; COLOR BEL
hex1b 5d 31 37 3b ... 07

Description

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

bash
printf '\033]17;#45475a\007'   # set selection bg\nprintf '\033]17;?\007'         # query
python
import sys; sys.stdout.write('\x1b]17;#45475a\x07')
go
fmt.Print("\x1b]17;#45475a\x07")
javascript
process.stdout.write('\x1b]17;#45475a\x07')
c
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

Related sequences