Skip to main content
ansicode

SGR 7 — Reverse video

Swap foreground and background colors.

Byte forms

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

\\x1b[\x1b[7m
\\033[\033[7m
\\e[\e[7m
ESC [ESC [ 7 m
hex1b 5b 37 6d

Description

Swaps the current foreground and background colors. Universally supported across xterm, Linux console, cmd, every Mac/Linux terminal, and Windows Terminal. Disable with `\x1b[27m`. Often used by status bars and selection highlighting; combine with explicit fg/bg if you want the highlighted color to be consistent across terminal themes.

Spec citation: ECMA-48 §8.3.117 (SGR parameter 7)

Examples

bash
printf '\033[7m highlighted \033[0m\n'
python
print('\x1b[7m highlighted \x1b[0m')
go
fmt.Print("\x1b[7m highlighted \x1b[0m")
javascript
console.log('\x1b[7m highlighted \x1b[0m')
c
printf("\x1b[7m highlighted \x1b[0m\n");

Terminal support

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

Related sequences