ANSI escape code cheatsheet
The ~30 codes you reach for most often, grouped into four print-friendly tables: text attributes, foreground / background colour, cursor + erase, and modes + OSC. Hit Print to drop the navigation chrome and fit one page; each row links to the canonical sequence page for byte forms, parameters, and per-terminal support.
Tip: print preview (Cmd/Ctrl-P) removes the header, footer, and navigation so the four tables fit on a single sheet.
Text attributes (SGR)
| Bytes | Meaning |
|---|---|
| \x1b[0m | Reset / normal |
| \x1b[1m | Bold / increased intensity |
| \x1b[2m | Dim / decreased intensity |
| \x1b[3m | Italic |
| \x1b[4m | Underline |
| \x1b[7m | Reverse video (swap fg / bg) |
| \x1b[9m | Strikethrough |
| \x1b[22m \x1b[23m \x1b[24m \x1b[27m | Turn off bold/dim · italic · underline · reverse |
Foreground / background colour
| Bytes | Meaning |
|---|---|
| \x1b[30m … \x1b[37m | Basic 8 foreground (black, red, green, yellow, blue, magenta, cyan, white) |
| \x1b[40m … \x1b[47m | Basic 8 background |
| \x1b[90m … \x1b[97m | Bright 8 foreground (a.k.a. high-intensity) |
| \x1b[100m … \x1b[107m | Bright 8 background |
| \x1b[38;5;Nm \x1b[48;5;Nm | 256-colour palette — N is 0–255 (16 system + 6×6×6 cube + 24 greys) |
| \x1b[38;2;R;G;Bm \x1b[48;2;R;G;Bm | Truecolor (24-bit RGB) — R/G/B each 0–255 |
| \x1b[39m \x1b[49m | Default foreground · default background |
Cursor & erase
| Bytes | Meaning |
|---|---|
| \x1b[<n>A B C D | Move cursor up / down / forward / back by n cells |
| \x1b[<row>;<col>H | Cursor position — 1-based (CUP / HVP) |
| \x1b[s \x1b[u | Save / restore cursor position (SCO) |
| \x1b[2J | Erase entire screen (ED 2) |
| \x1b[2K | Erase entire line (EL 2) |
| \x1b[?25l \x1b[?25h | Hide / show cursor (DECTCEM) |
Modes & OSC
| Bytes | Meaning |
|---|---|
| \x1b[?1049h \x1b[?1049l | Enter / leave alternate screen buffer |
| \x1b[?2004h \x1b[?2004l | Enable / disable bracketed paste mode |
| \x1b]0;<title>\x07 | Set window + icon title (OSC 0 — BEL terminator) |
| \x1b]8;;<url>\x1b\\<text>\x1b]8;;\x1b\\ | Hyperlink (OSC 8 — ST terminator) |
| \x1bc | Full reset (RIS) |
| \x1b[!p | Soft reset (DECSTR — keeps screen contents) |
See also
ansicode.eversources.app/en/cheatsheet · ECMA-48 · xterm-ctlseqs