Hammer Meet Nail
Ctrl+K

ANSI Escape Codes

What each escape sequence does, shown on your own text

Notation

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.

SequenceNameWhat it doesOn your textSource
\x1b[0mResetClears 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[1mBoldIncreased 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 ownECMA-48
\x1b[2mFaintDecreased intensity. How faint is the terminal’s choice, and a few ignore it entirely.The quick brown fox terminal’s ownECMA-48
\x1b[3mItalicSlanted text, where the terminal has an italic face to draw it with.The quick brown fox ECMA-48
\x1b[4mUnderlineA single line under the text.The quick brown fox ECMA-48
\x1b[5mSlow blinkThe 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 hereECMA-48
\x1b[6mRapid blinkThe text blinks 150 times a minute or faster. Almost nothing implements it, and the same refusal to animate applies.not shown hereECMA-48
\x1b[7mReverse videoSwaps foreground and background. Used for selections and status lines, and it survives whatever colors are already set.The quick brown fox ECMA-48
\x1b[8mConcealThe 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[9mCrossed outA line through the text.The quick brown fox ECMA-48
\x1b[21mDoubly underlinedTwo 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[51mFramedA frame drawn around the text. Effectively unimplemented; a border here would be an approximation of an effect nothing produces.not shown hereECMA-48
\x1b[52mEncircledThe text ringed rather than boxed. Effectively unimplemented, like 51.not shown hereECMA-48
\x1b[53mOverlinedA line above the text.The quick brown fox ECMA-48
\x1b[60–65mIdeogram attributesUnderlines, overlines and stress marks for ideographic text — 60 to 64 turn them on, 65 turns them off. Effectively unimplemented.not shown hereECMA-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.

SequenceNameWhat it doesOn your textSource
\x1b[22mNormal intensityNeither bold nor faint — turns off 1 and 2 together.The quick brown fox ECMA-48
\x1b[23mNot italicTurns off 3, and Fraktur with it.The quick brown fox ECMA-48
\x1b[24mNot underlinedTurns off 4 and 21 alike.The quick brown fox ECMA-48
\x1b[25mNot blinkingTurns off 5 and 6.The quick brown fox ECMA-48
\x1b[27mNot reversedTurns off 7, putting foreground and background back where they were.The quick brown fox ECMA-48
\x1b[28mRevealTurns off 8, drawing concealed text again.The quick brown fox ECMA-48
\x1b[29mNot crossed outTurns off 9.The quick brown fox ECMA-48
\x1b[54mNot framed or encircledTurns off 51 and 52.The quick brown fox ECMA-48
\x1b[55mNot overlinedTurns 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.

SequenceNameWhat it doesOn your textSource
\x1b[10mPrimary fontBack to the terminal’s default font, undoing 11 to 19.The quick brown fox ECMA-48
\x1b[11–19mAlternative fontSelects 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 hereECMA-48
\x1b[20mFrakturBlackletter text. Effectively unimplemented.not shown hereECMA-48
\x1b[26mProportional spacingReserved 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 hereECMA-48
\x1b[50mDisable proportional spacingReserved alongside 26, cancelling whatever 26 set.not shown hereECMA-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.

SequenceNameWhat it doesOn your textSource
\x1b[30mBlackDraws the text in the terminal’s black. Which black that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[31mRedDraws the text in the terminal’s red. Which red that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[32mGreenDraws the text in the terminal’s green. Which green that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[33mYellowDraws the text in the terminal’s yellow. Which yellow that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[34mBlueDraws the text in the terminal’s blue. Which blue that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[35mMagentaDraws the text in the terminal’s magenta. Which magenta that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[36mCyanDraws the text in the terminal’s cyan. Which cyan that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[37mWhiteDraws the text in the terminal’s white. Which white that is comes from the theme.The quick brown fox terminal’s ownECMA-48
\x1b[38;5;nm256-color foregroundOne 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;bm24-bit foregroundAn 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[39mDefault foregroundBack to whatever the terminal draws unstyled text in.The quick brown fox terminal’s ownECMA-48
\x1b[90mBright blackDraws 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 ownaixterm
\x1b[91mBright redDraws 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 ownaixterm
\x1b[92mBright greenDraws 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 ownaixterm
\x1b[93mBright yellowDraws 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 ownaixterm
\x1b[94mBright blueDraws 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 ownaixterm
\x1b[95mBright magentaDraws 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 ownaixterm
\x1b[96mBright cyanDraws 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 ownaixterm
\x1b[97mBright whiteDraws 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 ownaixterm

Background colors

The color behind the text, in the same three forms as the foreground.

SequenceNameWhat it doesOn your textSource
\x1b[40mBlack backgroundFills the text’s background with the terminal’s black.The quick brown fox terminal’s ownECMA-48
\x1b[41mRed backgroundFills the text’s background with the terminal’s red.The quick brown fox terminal’s ownECMA-48
\x1b[42mGreen backgroundFills the text’s background with the terminal’s green.The quick brown fox terminal’s ownECMA-48
\x1b[43mYellow backgroundFills the text’s background with the terminal’s yellow.The quick brown fox terminal’s ownECMA-48
\x1b[44mBlue backgroundFills the text’s background with the terminal’s blue.The quick brown fox terminal’s ownECMA-48
\x1b[45mMagenta backgroundFills the text’s background with the terminal’s magenta.The quick brown fox terminal’s ownECMA-48
\x1b[46mCyan backgroundFills the text’s background with the terminal’s cyan.The quick brown fox terminal’s ownECMA-48
\x1b[47mWhite backgroundFills the text’s background with the terminal’s white.The quick brown fox terminal’s ownECMA-48
\x1b[48;5;nm256-color backgroundThe 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;bm24-bit backgroundAn exact background color, exactly as 38;2 — the colon spelling included. Shown with 30;41;59.The quick brown fox ISO 8613-6
\x1b[49mDefault backgroundBack to the terminal’s own background.The quick brown fox terminal’s ownECMA-48
\x1b[100mBright black backgroundFills the background with the terminal’s bright black. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm
\x1b[101mBright red backgroundFills the background with the terminal’s bright red. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm
\x1b[102mBright green backgroundFills the background with the terminal’s bright green. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm
\x1b[103mBright yellow backgroundFills the background with the terminal’s bright yellow. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm
\x1b[104mBright blue backgroundFills the background with the terminal’s bright blue. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm
\x1b[105mBright magenta backgroundFills the background with the terminal’s bright magenta. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm
\x1b[106mBright cyan backgroundFills the background with the terminal’s bright cyan. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm
\x1b[107mBright white backgroundFills the background with the terminal’s bright white. The aixterm range, like 90–97.The quick brown fox terminal’s ownaixterm

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.

SequenceNameWhat it doesOn your textSource
\x1b[58;5;nmUnderline colorColors 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;bm24-bit underline colorThe 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[59mDefault underline colorThe 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.

SequenceNameWhat it doesOn your textSource
\x1b[2JClear screenErases the whole screen. What the scrollback keeps is the terminal’s business, which is why clear and reset differ.not shown hereECMA-48
\x1b[HCursor homeMoves the cursor to row 1, column 1. Paired with clear screen, it is how a program starts a frame.not shown hereECMA-48
\x1b[2KErase lineErases the line the cursor is on, leaving the cursor where it was. How a progress line rewrites itself.not shown hereECMA-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.