ANSI Escape Codes
What each escape sequence does, shown on your own text
Read a pasted string
Output out of a log or a CI run, rendered as a terminal would show it — nothing is run, connected to, or reported on.
The sequences
Attributes
Select Graphic Rendition — how the text is drawn. These are the sequences that turn up in logs and prompts.
| Sequence | Name | What it does | On your text | Source |
|---|---|---|---|---|
\x1b[0m | Reset | Clears every attribute at once — color, weight, underline, the lot — back to the terminal’s defaults. The sequence that ends a colored run. | The quick brown fox | ECMA-48 |
\x1b[1m | Bold | Increased intensity. Most terminals draw a bold face; some brighten the color instead, which is why bold text sometimes changes hue rather than weight. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[2m | Faint | Decreased intensity. How faint is the terminal’s choice, and a few ignore it entirely. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[3m | Italic | Slanted text, where the terminal has an italic face to draw it with. | The quick brown fox | ECMA-48 |
\x1b[4m | Underline | A single line under the text. | The quick brown fox | ECMA-48 |
\x1b[5m | Slow blink | The text blinks, under 150 times a minute. Named here rather than animated: a still row pretending to blink teaches the wrong thing about the sequence, and most terminals refuse it too. | not shown here | ECMA-48 |
\x1b[6m | Rapid blink | The text blinks 150 times a minute or faster. Almost nothing implements it, and the same refusal to animate applies. | not shown here | ECMA-48 |
\x1b[7m | Reverse video | Swaps foreground and background. Used for selections and status lines, and it survives whatever colors are already set. | The quick brown fox | ECMA-48 |
\x1b[8m | Conceal | The text is not drawn. It is still in the output — selecting and copying takes it — so this hides nothing from anyone holding the bytes. | The quick brown fox | ECMA-48 |
\x1b[9m | Crossed out | A line through the text. | The quick brown fox | ECMA-48 |
\x1b[21m | Doubly underlined | Two lines under the text, as ECMA-48 defines it. In practice the least portable of the underline codes: a number of terminals treat 21 as bold off instead, which is 22’s job. | The quick brown fox | ECMA-48 |
\x1b[51m | Framed | A frame drawn around the text. Effectively unimplemented; a border here would be an approximation of an effect nothing produces. | not shown here | ECMA-48 |
\x1b[52m | Encircled | The text ringed rather than boxed. Effectively unimplemented, like 51. | not shown here | ECMA-48 |
\x1b[53m | Overlined | A line above the text. | The quick brown fox | ECMA-48 |
\x1b[60–65m | Ideogram attributes | Underlines, overlines and stress marks for ideographic text — 60 to 64 turn them on, 65 turns them off. Effectively unimplemented. | not shown here | ECMA-48 |
Turning attributes off
Each attribute has its own off switch, so a run can end one effect without resetting the rest. 0 resets the lot.
| Sequence | Name | What it does | On your text | Source |
|---|---|---|---|---|
\x1b[22m | Normal intensity | Neither bold nor faint — turns off 1 and 2 together. | The quick brown fox | ECMA-48 |
\x1b[23m | Not italic | Turns off 3, and Fraktur with it. | The quick brown fox | ECMA-48 |
\x1b[24m | Not underlined | Turns off 4 and 21 alike. | The quick brown fox | ECMA-48 |
\x1b[25m | Not blinking | Turns off 5 and 6. | The quick brown fox | ECMA-48 |
\x1b[27m | Not reversed | Turns off 7, putting foreground and background back where they were. | The quick brown fox | ECMA-48 |
\x1b[28m | Reveal | Turns off 8, drawing concealed text again. | The quick brown fox | ECMA-48 |
\x1b[29m | Not crossed out | Turns off 9. | The quick brown fox | ECMA-48 |
\x1b[54m | Not framed or encircled | Turns off 51 and 52. | The quick brown fox | ECMA-48 |
\x1b[55m | Not overlined | Turns off 53. | The quick brown fox | ECMA-48 |
Fonts and spacing
ECMA-48 gives SGR a font bank and proportional spacing. A terminal is a grid of cells carrying no alternative fonts, so this is the corner of SGR nothing implements.
| Sequence | Name | What it does | On your text | Source |
|---|---|---|---|---|
\x1b[10m | Primary font | Back to the terminal’s default font, undoing 11 to 19. | The quick brown fox | ECMA-48 |
\x1b[11–19m | Alternative font | Selects alternative fonts 1 to 9 from a bank the terminal is meant to carry. Almost none carry one, so in practice these change nothing. | not shown here | ECMA-48 |
\x1b[20m | Fraktur | Blackletter text. Effectively unimplemented. | not shown here | ECMA-48 |
\x1b[26m | Proportional spacing | Reserved rather than defined: ECMA-48 sets 26 aside for the proportional spacing of CCITT T.61. A terminal is a grid of fixed cells, and nothing implements it. | not shown here | ECMA-48 |
\x1b[50m | Disable proportional spacing | Reserved alongside 26, cancelling whatever 26 set. | not shown here | ECMA-48 |
Foreground colors
The color the text is drawn in. The eight base colors and their bright counterparts are named rather than defined — the values come from your terminal’s theme.
| Sequence | Name | What it does | On your text | Source |
|---|---|---|---|---|
\x1b[30m | Black | Draws the text in the terminal’s black. Which black that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[31m | Red | Draws the text in the terminal’s red. Which red that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[32m | Green | Draws the text in the terminal’s green. Which green that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[33m | Yellow | Draws the text in the terminal’s yellow. Which yellow that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[34m | Blue | Draws the text in the terminal’s blue. Which blue that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[35m | Magenta | Draws the text in the terminal’s magenta. Which magenta that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[36m | Cyan | Draws the text in the terminal’s cyan. Which cyan that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[37m | White | Draws the text in the terminal’s white. Which white that is comes from the theme. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[38;5;nm | 256-color foreground | One of 256 colors, n from 0 to 255: 0–15 are the same theme colors 30–37 and 90–97 name, 16–231 a fixed 6×6×6 cube, 232–255 a 24-step grey ramp. ECMA-48 reserves 38 rather than defining it, and the indexed form is xterm’s; the colon spelling 38:5:n is read here too. Shown with n = 208. | The quick brown fox | xterm control sequences |
\x1b[38;2;r;g;bm | 24-bit foreground | An exact color, each channel 0 to 255. ECMA-48 reserves 38 and points at ISO 8613-6 for this; the ISO spelling separates with colons — 38:2:r:g:b, and 38:2::r:g:b with the color-space slot left empty — both read here. A terminal without truecolor rounds it to the nearest palette entry rather than refusing it. Shown with 255;105;180. | The quick brown fox | ISO 8613-6 |
\x1b[39m | Default foreground | Back to whatever the terminal draws unstyled text in. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[90m | Bright black | Draws the text in the terminal’s bright black. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
\x1b[91m | Bright red | Draws the text in the terminal’s bright red. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
\x1b[92m | Bright green | Draws the text in the terminal’s bright green. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
\x1b[93m | Bright yellow | Draws the text in the terminal’s bright yellow. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
\x1b[94m | Bright blue | Draws the text in the terminal’s bright blue. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
\x1b[95m | Bright magenta | Draws the text in the terminal’s bright magenta. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
\x1b[96m | Bright cyan | Draws the text in the terminal’s bright cyan. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
\x1b[97m | Bright white | Draws the text in the terminal’s bright white. Not in ECMA-48 — the aixterm range every modern terminal carries, and the reason bold text and bright text are so often confused. | The quick brown fox terminal’s own | aixterm |
Background colors
The color behind the text, in the same three forms as the foreground.
| Sequence | Name | What it does | On your text | Source |
|---|---|---|---|---|
\x1b[40m | Black background | Fills the text’s background with the terminal’s black. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[41m | Red background | Fills the text’s background with the terminal’s red. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[42m | Green background | Fills the text’s background with the terminal’s green. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[43m | Yellow background | Fills the text’s background with the terminal’s yellow. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[44m | Blue background | Fills the text’s background with the terminal’s blue. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[45m | Magenta background | Fills the text’s background with the terminal’s magenta. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[46m | Cyan background | Fills the text’s background with the terminal’s cyan. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[47m | White background | Fills the text’s background with the terminal’s white. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[48;5;nm | 256-color background | The background from the 256-color palette, exactly as 38;5;n — reserved in ECMA-48 alike, and read in the colon spelling too. Shown with n = 226. | The quick brown fox | xterm control sequences |
\x1b[48;2;r;g;bm | 24-bit background | An exact background color, exactly as 38;2 — the colon spelling included. Shown with 30;41;59. | The quick brown fox | ISO 8613-6 |
\x1b[49m | Default background | Back to the terminal’s own background. | The quick brown fox terminal’s own | ECMA-48 |
\x1b[100m | Bright black background | Fills the background with the terminal’s bright black. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
\x1b[101m | Bright red background | Fills the background with the terminal’s bright red. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
\x1b[102m | Bright green background | Fills the background with the terminal’s bright green. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
\x1b[103m | Bright yellow background | Fills the background with the terminal’s bright yellow. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
\x1b[104m | Bright blue background | Fills the background with the terminal’s bright blue. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
\x1b[105m | Bright magenta background | Fills the background with the terminal’s bright magenta. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
\x1b[106m | Bright cyan background | Fills the background with the terminal’s bright cyan. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
\x1b[107m | Bright white background | Fills the background with the terminal’s bright white. The aixterm range, like 90–97. | The quick brown fox terminal’s own | aixterm |
Underline color
Coloring the underline apart from the text. Not ECMA-48 — an extension, carried here marked as one, because editors and linters emit it.
| Sequence | Name | What it does | On your text | Source |
|---|---|---|---|---|
\x1b[58;5;nm | Underline color | Colors the underline from the 256-color palette, leaving the text its own color. ECMA-48 reserves 56–59 rather than defining them; terminals took 58 to work exactly as 38 does. Shown with 4 as well, so there is a line to color. | The quick brown fox | kitty |
\x1b[58;2;r;g;bm | 24-bit underline color | The underline in an exact color, as 38;2 does for the text. Shown with 4 and 255;105;180. | The quick brown fox | kitty |
\x1b[59m | Default underline color | The underline back to the text’s own color. | The quick brown fox | kitty |
Screen control
SGR is carried whole above. Of the rest of the escape family — cursor movement, scrolling regions, mode switches — only these three are here, the ones people actually meet. Anything else is outside this table, and a paste carrying it is told so rather than half-read.
| Sequence | Name | What it does | On your text | Source |
|---|---|---|---|---|
\x1b[2J | Clear screen | Erases the whole screen. What the scrollback keeps is the terminal’s business, which is why clear and reset differ. | not shown here | ECMA-48 |
\x1b[H | Cursor home | Moves the cursor to row 1, column 1. Paired with clear screen, it is how a program starts a frame. | not shown here | ECMA-48 |
\x1b[2K | Erase line | Erases the line the cursor is on, leaving the cursor where it was. How a progress line rewrites itself. | not shown here | ECMA-48 |
Sequences and their meanings as ECMA-48 defines them, the indexed and direct color forms as the xterm control sequences document records them; each row names its own. ECMA-48 reserves 38, 48 and 56–59 rather than defining them: the color forms come from ISO 8613-6, the bright ranges 90–97 and 100–107 from aixterm, and 58 and 59 from kitty. The 256-color values drawn here are xterm’s compiled-in defaults — one rendering, not your terminal’s theme.