Skip to main content
ansicode

SGR 0 — Reset / Normal

Clear all text attributes and colors back to the terminal default.

Byte forms

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

\\x1b[\x1b[0m
\\033[\033[0m
\\e[\e[0m
ESC [ESC [ 0 m
hex1b 5b 30 6d

Description

SGR 0 (Select Graphic Rendition with parameter 0) resets every text attribute the terminal is currently tracking — foreground color, background color, bold, italic, underline, reverse video, blink, etc. It is equivalent to \x1b[m (the parameter defaults to 0 when omitted) and to \x1b[;m (an empty parameter list is treated as a single 0). The five bytes 1b 5b 30 6d are the most-emitted ANSI escape in the wild: almost every other styled output ends with them.

The canonical failure mode this fixes is color bleed: forgetting to reset means the next prompt, the next log line, even the shell prompt itself inherits the last attribute you set. Once bled into the shell's own readline buffer, every keystroke afterwards is colored until the user runs reset or opens a new terminal. Treat color like a try/finally resource — open with \x1b[…m, close with \x1b[0m, on every code path including panics and signal handlers. Pipes that buffer mid-line (tee, grep, less without -R) make leaks worse: the reset gets dropped, only the opener lands. Pair with the /pitfalls/no-reset-color-bleed guide for recovery recipes.

When you want to clear only part of the state, use the narrower disables instead of a full reset: \x1b[39m resets foreground color only, \x1b[49m background only, \x1b[22m bold + dim, \x1b[23m italic, \x1b[24m underline. These compose — e.g. \x1b[39;49m clears both colors but leaves bold / underline alone. For an even stronger reset that also returns the terminal to its power-on state (clearing scroll region, alt-screen, mouse modes, etc.) see decstr-soft-reset (\x1b[!p) or the RIS hard reset \x1bc.

Spec citation: ECMA-48 §8.3.117 (SGR)

Examples

bash
printf '\033[31merror\033[0m\n'
python
print('\x1b[31merror\x1b[0m')
go
fmt.Print("\x1b[31merror\x1b[0m")
javascript
process.stdout.write('\x1b[31merror\x1b[0m\n')
c
printf("\x1b[31merror\x1b[0m\n");

Used in

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

  • ls --color, grep --colorappended after every coloured chunk so the next file/match starts clean
  • git diff, git log
  • npm, pnpm, yarn progress lines
  • starship, oh-my-zsh, powerlevel10k prompts
  • gcc, clang diagnostics

Frequently asked

Short answers to the questions developers actually search for this sequence.

Does \x1b[m mean the same as \x1b[0m?
Yes. ECMA-48 §5.4.2 specifies that an omitted SGR parameter defaults to 0, so \x1b[m and \x1b[;m both reset every attribute exactly as \x1b[0m does. Every terminal in the support matrix honours this — pick whichever spelling reads cleanest in your codebase.
Why does my shell prompt stay coloured after my program prints text?
You opened an SGR attribute but never closed it — the terminal keeps applying the last colour until *something* emits \x1b[0m. Treat colour like a try/finally resource: every \x1b[31m (or similar) must be paired with a reset, including on panic / signal-handler paths. See the color-bleed pitfall for the full recovery recipe.
How do I reset only the foreground colour without losing bold or underline?
Use the narrower disables instead of SGR 0: \x1b[39m resets foreground only, \x1b[49m background only, \x1b[22m clears bold + dim, \x1b[23m italic, \x1b[24m underline. They compose — \x1b[39;49m clears both colours but leaves weight and underline intact.

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 · 1. One-shot reset — `\x1b[0m`