Skip to main content
ansicode

SGR 39 — Default foreground color

Reset only the foreground color (leaves attributes + bg intact).

Byte forms

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

\\x1b[\x1b[39m
\\033[\033[39m
\\e[\e[39m
ESC [ESC [ 3 9 m
hex1b 5b 33 39 6d

Live preview

Rendered in your browser via the same tokeniser the decoder uses — no terminal needed.

red fg back to default fg

Description

ECMA-48 §8.3.117 names SGR 39 "default display colour" — the byte sequence is \x1b[39m, CSI followed by 3 9 then the final byte m. Resets the foreground channel only — background, bold, italic, underline, blink, reverse, strikethrough, and every other SGR attribute is left untouched. The complement of \x1b[49m (SGR 49, default background). The "default" foreground is whichever colour the user's theme assigns to non-coloured text — usually near-white on dark themes and near-black on light themes — not a fixed RGB value, which means a foreground that prints fine on the operator's terminal can be near-invisible on a user's inverted theme.

Portability — universal among VTxxx-derived emulators (xterm, iTerm2, kitty, alacritty, wezterm, gnome-terminal, Konsole, Ghostty), Linux console, modern Windows Terminal, and ConPTY 1809+. A pre-VT220 surprise survives in a few very old emulators that treated SGR 39 as "reset all" — modern code can ignore this, but it explains why some legacy docs still warn "don't use 39, use SGR 0 + re-apply attributes." The terminfo cap op (orig pair) emits \x1b[39;49m, the canonical "reset just the two colour channels" pair. tmux passes SGR 39 through unmodified. Windows legacy cmd.exe (pre-ConPTY) did not recognise SGR 39 at all — whatever foreground was active stayed active.

SGR 39 *is* itself the close — there is no separate "default-foreground close" because the default state is the close. The most useful compound is \x1b[39;49m (or equivalently tput op), which drops both colour channels without disturbing bold / italic / underline — exactly the recipe for "return to plain colours but keep emphasis." Don't confuse SGR 39 with SGR 0 (sgr-reset); SGR 0 strips every attribute including bold and underline, where SGR 39 surgically resets only the foreground colour. Related: sgr-fg-basic (SGR 30-37, basic 8-colour foreground that SGR 39 closes), sgr-default-bg (SGR 49, the matching background reset), sgr-reset (SGR 0, full attribute reset).

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

Examples

bash
printf '\033[1;31mERROR\033[39m bold continues\033[0m\n'
python
print('\x1b[31mred\x1b[39m default\x1b[0m')
go
fmt.Print("\x1b[31mred\x1b[39m default\x1b[0m")
javascript
console.log('\x1b[31mred\x1b[39m default\x1b[0m')
c
printf("\x1b[31mred\x1b[39m default\x1b[0m\n");

Used in

Real-world tools that emit this sequence — anchors the bytes to commands you've already used.

  • chalk (Node) reset helpers`chalk.reset.fg` only resets foreground, leaving any active bg in place
  • colorama (Python) Fore.RESETemits SGR 39, narrower than SGR 0 — keeps Style.BRIGHT and any Back.* set
  • fatih/color (Go) ResetForegroundleaves background and attribute state untouched
  • lipgloss / charmbracelet apps — scoped fg reset between segments
  • ncurses A_NORMAL on a fg-only attribute

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
yes
GNU screen
yes

Related sequences

In the family cookbook

SGR cookbook · 2. 16-color basic — `\x1b[31m` and friends