encyclopegia.org

ANSI escape code

ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators.[src] Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text.[src] The terminal interprets these sequences as commands, rather than text to display verbatim.[src] ANSI codes can change the color of text and move the cursor so text can be drawn anywhere on the screen.[src] ANSI sequences were introduced in the 1970s to replace vendor-specific sequences and became widespread in the computer equipment market by the early 1980s.[src] Although hardware text terminals have become increasingly rare in the 21st century, the relevance of the ANSI standard persists because a great majority of terminal emulators and command consoles interpret at least a portion of the ANSI standard.[src] ANSI stands for "American National Standards Institute".[src]

ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators.[src] Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text.[src] The terminal interprets these sequences as commands, rather than text to display verbatim.[src] ANSI codes can change the color of text and move the cursor so text can be drawn anywhere on the screen.[src] ANSI sequences were introduced in the 1970s to replace vendor-specific sequences and became widespread in the computer equipment market by the early 1980s.[src] Although hardware text terminals have become increasingly rare in the 21st century, the relevance of the ANSI standard persists because a great majority of terminal emulators and command consoles interpret at least a portion of the ANSI standard.[src] ANSI stands for "American National Standards Institute".[src] == Control Sequence Introducer commands == For Control Sequence Introducer, or CSI, commands, the (written as , or in several programming languages) is followed by any number (including none) of "parameter bytes" in the range 0x30–0x3F (ASCII 0–9:; ?[src] ), then by any number of "intermediate bytes" in the range 0x20–0x2F (ASCII space and ), then finally by a single "final byte" in the range 0x40–0x7E (ASCII @A–Z[\]^_`a–z ~ ) are private.[src] The behavior of the terminal is undefined in the case where a CSI sequence contains any character outside of the range 0x20–0x7E.[src] These illegal characters are either C0 control characters (the range 0–0x1F), DEL (0x7F), or bytes with the high bit set.[src] Possible responses are to ignore the byte, to process it immediately, and furthermore whether to continue with the CSI sequence, to abort it immediately, or to ignore the rest of it.[src] == Select Graphic Rendition parameters == The control sequence CSI m , named Select Graphic Rendition (SGR), sets display attributes.[src] Several attributes can be set in the same sequence, separated by semicolons.[src] Each display attribute remains in effect until a following occurrence of SGR resets it.[src] If no codes are given, is treated as (reset / normal).[src] === Colors === ==== 3-bit and 4-bit ==== The original specification only had 8 colors, and just gave them names.[src] The SGR parameters 30–37 selected the foreground color, while 40–47 selected the background.[src] Quite a few terminals implemented "bold" (SGR code 1) as a brighter color rather than a different font, thus providing 8 additional foreground colors.[src] Usually you could not get these as background colors, though sometimes inverse video (SGR code 7) would allow that.[src] Examples: to get black letters on white background use , to get red use , to get bright red use .[src] To reset colors to their defaults, use (not supported on some terminals), or reset all attributes with .[src] Later terminals added the ability to directly specify the "bright" colors with 90–97 and 100–107.[src] The chart below shows a few examples of how classical standards and modern terminal emulators translate the 4-bit color codes into 24-bit color codes.[src] |- style="height:2.5em;vertical-align:bottom" | colspan="36" | 216 colors |- | style="color:#ffffff;background:#000000;" title="#000000" |16 | style="color:#ffffff;background:#00005f;" title="#00005f" |17 | style="color:#ffffff;background:#000087;" title="#000087" |18 | style="color:#ffffff;background:#0000af;" title="#0000af" |19 | style="color:#ffffff;background:#0000d7;" title="#0000d7" |20 | style="color:#ffffff;background:#0000ff;" title="#0000ff" |21 | style="color:#ffffff;background:#005f00;" title="#005f00" |22 | style="color:#ffffff;background:#005f5f;" title="#005f5f" |23 | style="color:#ffffff;background:#005f87;" title="#005f87" |24 | style="color:#ffffff;background:#005faf;" title="#005faf" |25 | style="color:#ffffff;background:#005fd7;" title="#005fd7" |26 | style="color:#ffffff;background:#005fff;" title="#005fff" |27 | style="color:#ffffff;background:#008700;" title="#008700" |28 | style="color:#ffffff;background:#00875f;" title="#00875f" |29 | style="color:#ffffff;background:#008787;" title="#008787" |30 | style="color:#ffffff;background:#0087af;" title="#0087af" |31 | style="color:#ffffff;background:#0087d7;" title="#0087d7" |32 | style="color:#ffffff;background:#0087ff;" title="#0087ff" |33 | style="color:#000000;background:#00af00;" title="#00af00" |34 | style="color:#000000;background:#00af5f;" title="#00af5f" |35 | style="color:#000000;background:#00af87;" title="#00af87" |36 | style="color:#000000;background:#00afaf;" title="#00afaf" |37 | style="color:#000000;background:#00afd7;" title="#00afd7" |38 | style="color:#000000;background:#00afff;" title="#00afff" |39 | style="color:#000000;background:#00d700;" title="#00d700" |40 | style="color:#000000;background:#00d75f;" title="#00d75f" |41 | style="color:#000000;background:#00d787;" title="#00d787" |42 | style="color:#000000;background:#00d7af;" title="#00d7af" |43 | style="color:#000000;background:#00d7d7;" title="#00d7d7" |44 | style="color:#000000;background:#00d7ff;" title="#00d7ff" |45 | style="color:#000000;background:#00ff00;" title="#00ff00" |46 | style="color:#000000;background:#00ff5f;" title="#00ff5f" |47 | style="color:#000000;background:#00ff87;" title="#00ff87" |48 | style="color:#000000;background:#00ffaf;" title="#00ffaf" |49 | style="color:#000000;background:#00ffd7;" title="#00ffd7" |50 | style="color:#000000;background:#00ffff;" title="#00ffff" |51 |- | style="color:#ffffff;background:#5f0000;" title="#5f0000" |52 | style="color:#ffffff;background:#5f005f;" title="#5f005f" |53 | style="color:#ffffff;background:#5f0087;" title="#5f0087" |54 | style="color:#ffffff;background:#5f00af;" title="#5f00af" |55 | style="color:#ffffff;background:#5f00d7;" title="#5f00d7" |56 | style="color:#ffffff;background:#5f00ff;" title="#5f00ff" |57 | style="color:#ffffff;background:#5f5f00;" title="#5f5f00" |58 | style="color:#ffffff;background:#5f5f5f;" title="#5f5f5f" |59 | style="color:#ffffff;background:#5f5f87;" title="#5f5f87" |60 | style="color:#ffffff;background:#5f5faf;" title="#5f5faf" |61 | style="color:#ffffff;background:#5f5fd7;" title="#5f5fd7" |62 | style="color:#ffffff;background:#5f5fff;" title="#5f5fff" |63 | style="color:#ffffff;background:#5f8700;" title="#5f8700" |64 | style="color:#ffffff;background:#5f875f;" title="#5f875f" |65 | style="color:#ffffff;background:#5f8787;" title="#5f8787" |66 | style="color:#ffffff;background:#5f87af;" title="#5f87af" |67 | style="color:#ffffff;background:#5f87d7;" title="#5f87d7" |68 | style="color:#ffffff;background:#5f87ff;" title="#5f87ff" |69 | style="color:#000000;background:#5faf00;" title="#5faf00" |70 | style="color:#000000;background:#5faf5f;" title="#5faf5f" |71 | style="color:#000000;background:#5faf87;" title="#5faf87" |72 | style="color:#000000;background:#5fafaf;" title="#5fafaf" |73 | style="color:#000000;background:#5fafd7;" title="#5fafd7" |74 | style="color:#000000;background:#5fafff;" title="#5fafff" |75 | style="color:#000000;background:#5fd700;" title="#5fd700" |76 | style="color:#000000;background:#5fd75f;" title="#5fd75f" |77 | style="color:#000000;background:#5fd787;" title="#5fd787" |78 | style="color:#000000;background:#5fd7af;" title="#5fd7af" |79 | style="color:#000000;background:#5fd7d7;" title="#5fd7d7" |80 | style="color:#000000;background:#5fd7ff;" title="#5fd7ff" |81 | style="color:#000000;background:#5fff00;" title="#5fff00" |82 | style="color:#000000;background:#5fff5f;" title="#5fff5f" |83 | style="color:#000000;background:#5fff87;" title="#5fff87" |84 | style="color:#000000;background:#5fffaf;" title="#5fffaf" |85 | style="color:#000000;background:#5fffd7;" title="#5fffd7" |86 | style="color:#000000;background:#5fffff;" title="#5fffff" |87 |- | style="color:#ffffff;background:#870000;" title="#870000" |88 | style="color:#ffffff;background:#87005f;" title="#87005f" |89 | style="color:#ffffff;background:#870087;" title="#870087" |90 | style="color:#ffffff;background:#8700af;" title="#8700af" |91 | style="color:#ffffff;background:#8700d7;" title="#8700d7" |92 | style="color:#ffffff;background:#8700ff;" title="#8700ff" |93 | style="color:#ffffff;background:#875f00;" title="#875f00" |94 | style="color:#ffffff;background:#875f5f;" title="#875f5f" |95 | style="color:#ffffff;background:#875f87;" title="#875f87" |96 | style="color:#ffffff;background:#875faf;" title="#875faf" |97 | style="color:#ffffff;background:#875fd7;" title="#875fd7" |98 | style="color:#ffffff;background:#875fff;" title="#875fff" |99 | style="color:#ffffff;background:#878700;" title="#878700" |100 | style="color:#ffffff;background:#87875f;" title="#87875f" |101 | style="color:#ffffff;background:#878787;" title="#878787" |102 | style="color:#ffffff;background:#8787af;" title="#8787af" |103 | style="color:#ffffff;background:#8787d7;" title="#8787d7" |104 | style="color:#ffffff;background:#8787ff;" title="#8787ff" |105 | style="color:#000000;background:#87af00;" title="#87af00" |106 | style="color:#000000;background:#87af5f;" title="#87af5f" |107 | style="color:#000000;background:#87af87;" title="#87af87" |108 | style="color:#000000;background:#87afaf;" title="#87afaf" |109 | style="color:#000000;background:#87afd7;" title="#87afd7" |110 | style="color:#000000;background:#87afff;" title="#87afff" |111 | style="color:#000000;background:#87d700;" title="#87d700" |112 | style="color:#000000;background:#87d75f;" title="#87d75f" |113 | style="color:#000000;background:#87d787;" title="#87d787" |114 | style="color:#000000;background:#87d7af;" title="#87d7af" |115 | style="color:#000000;background:#87d7d7;" title="#87d7d7" |116 | style="color:#000000;background:#87d7ff;" title="#87d7ff" |117 | style="color:#000000;background:#87ff00;" title="#87ff00" |118 | style="color:#000000;background:#87ff5f;" title="#87ff5f" |119 | style="color:#000000;background:#87ff87;" title="#87ff87" |120 | style="color:#000000;background:#87ffaf;" title="#87ffaf" |121 | style="color:#000000;background:#87ffd7;" title="#87ffd7" |122 | style="color:#000000;background:#87ffff;" title="#87ffff" |123 |- | style="color:#ffffff;background:#af0000;" title="#af0000" |124 | style="color:#ffffff;background:#af005f;" title="#af005f" |125 | style="color:#ffffff;background:#af0087;" title="#af0087" |126 | style="color:#ffffff;background:#af00af;" title="#af00af" |127 | style="color:#ffffff;background:#af00d7;" title="#af00d7" |128 | style="color:#ffffff;background:#af00ff;" title="#af00ff" |129 | style="color:#ffffff;background:#af5f00;" title="#af5f00" |130 | style="color:#ffffff;background:#af5f5f;" title="#af5f5f" |131 | style="color:#ffffff;background:#af5f87;" title="#af5f87" |132 | style="color:#ffffff;background:#af5faf;" title="#af5faf" |133 | style="color:#ffffff;background:#af5fd7;" title="#af5fd7" |134 | style="color:#ffffff;background:#af5fff;" title="#af5fff" |135 | style="color:#ffffff;background:#af8700;" title="#af8700" |136 | style="color:#ffffff;background:#af875f;" title="#af875f" |137 | style="color:#ffffff;background:#af8787;" title="#af8787" |138 | style="color:#ffffff;background:#af87af;" title="#af87af" |139 | style="color:#ffffff;background:#af87d7;" title="#af87d7" |140 | style="color:#ffffff;background:#af87ff;" title="#af87ff" |141 | style="color:#000000;background:#afaf00;" title="#afaf00" |142 | style="color:#000000;background:#afaf5f;" title="#afaf5f" |143 | style="color:#000000;background:#afaf87;" title="#afaf87" |144 | style="color:#000000;background:#afafaf;" title="#afafaf" |145 | style="color:#000000;background:#afafd7;" title="#afafd7" |146 | style="color:#000000;background:#afafff;" title="#afafff" |147 | style="color:#000000;background:#afd700;" title="#afd700" |148 | style="color:#000000;background:#afd75f;" title="#afd75f" |149 | style="color:#000000;background:#afd787;" title="#afd787" |150 | style="color:#000000;background:#afd7af;" title="#afd7af" |151 | style="color:#000000;background:#afd7d7;" title="#afd7d7" |152 | style="color:#000000;background:#afd7ff;" title="#afd7ff" |153 | style="color:#000000;background:#afff00;" title="#afff00" |154 | style="color:#000000;background:#afff5f;" title="#afff5f" |155 | style="color:#000000;background:#afff87;" title="#afff87" |156 | style="color:#000000;background:#afffaf;" title="#afffaf" |157 | style="color:#000000;background:#afffd7;" title="#afffd7" |158 | style="color:#000000;background:#afffff;" title="#afffff" |159 |- | style="color:#ffffff;background:#d70000;" title="#d70000" |160 | style="color:#ffffff;background:#d7005f;" title="#d7005f" |161 | style="color:#ffffff;background:#d70087;" title="#d70087" |162 | style="color:#ffffff;background:#d700af;" title="#d700af" |163 | style="color:#ffffff;background:#d700d7;" title="#d700d7" |164 | style="color:#ffffff;background:#d700ff;" title="#d700ff" |165 | style="color:#ffffff;background:#d75f00;" title="#d75f00" |166 | style="color:#ffffff;background:#d75f5f;" title="#d75f5f" |167 | style="color:#ffffff;background:#d75f87;" title="#d75f87" |168 | style="color:#ffffff;background:#d75faf;" title="#d75faf" |169 | style="color:#ffffff;background:#d75fd7;" title="#d75fd7" |170 | style="color:#ffffff;background:#d75fff;" title="#d75fff" |171 | style="color:#ffffff;background:#d78700;" title="#d78700" |172 | style="color:#ffffff;background:#d7875f;" title="#d7875f" |173 | style="color:#ffffff;background:#d78787;" title="#d78787" |174 | style="color:#ffffff;background:#d787af;" title="#d787af" |175 | style="color:#ffffff;background:#d787d7;" title="#d787d7" |176 | style="color:#ffffff;background:#d787ff;" title="#d787ff" |177 | style="color:#000000;background:#d7af00;" title="#d7af00" |178 | style="color:#000000;background:#d7af5f;" title="#d7af5f" |179 | style="color:#000000;background:#d7af87;" title="#d7af87" |180 | style="color:#000000;background:#d7afaf;" title="#d7afaf" |181 | style="color:#000000;background:#d7afd7;" title="#d7afd7" |182 | style="color:#000000;background:#d7afff;" title="#d7afff" |183 | style="color:#000000;background:#d7d700;" title="#d7d700" |184 | style="color:#000000;background:#d7d75f;" title="#d7d75f" |185 | style="color:#000000;background:#d7d787;" title="#d7d787" |186 | style="color:#000000;background:#d7d7af;" title="#d7d7af" |187 | style="color:#000000;background:#d7d7d7;" title="#d7d7d7" |188 | style="color:#000000;background:#d7d7ff;" title="#d7d7ff" |189 | style="color:#000000;background:#d7ff00;" title="#d7ff00" |190 | style="color:#000000;background:#d7ff5f;" title="#d7ff5f" |191 | style="color:#000000;background:#d7ff87;" title="#d7ff87" |192 | style="color:#000000;background:#d7ffaf;" title="#d7ffaf" |193 | style="color:#000000;background:#d7ffd7;" title="#d7ffd7" |194 | style="color:#000000;background:#d7ffff;" title="#d7ffff" |195 |- | style="color:#ffffff;background:#ff0000;" title="#ff0000" |196 | style="color:#ffffff;background:#ff005f;" title="#ff005f" |197 | style="color:#ffffff;background:#ff0087;" title="#ff0087" |198 | style="color:#ffffff;background:#ff00af;" title="#ff00af" |199 | style="color:#ffffff;background:#ff00d7;" title="#ff00d7" |200 | style="color:#ffffff;background:#ff00ff;" title="#ff00ff" |201 | style="color:#ffffff;background:#ff5f00;" title="#ff5f00" |202 | style="color:#ffffff;background:#ff5f5f;" title="#ff5f5f" |203 | style="color:#ffffff;background:#ff5f87;" title="#ff5f87" |204 | style="color:#ffffff;background:#ff5faf;" title="#ff5faf" |205 | style="color:#ffffff;background:#ff5fd7;" title="#ff5fd7" |206 | style="color:#ffffff;background:#ff5fff;" title="#ff5fff" |207 | style="color:#ffffff;background:#ff8700;" title="#ff8700" |208 | style="color:#ffffff;background:#ff875f;" title="#ff875f" |209 | style="color:#ffffff;background:#ff8787;" title="#ff8787" |210 | style="color:#ffffff;background:#ff87af;" title="#ff87af" |211 | style="color:#ffffff;background:#ff87d7;" title="#ff87d7" |212 | style="color:#ffffff;background:#ff87ff;" title="#ff87ff" |213 | style="color:#000000;background:#ffaf00;" title="#ffaf00" |214 | style="color:#000000;background:#ffaf5f;" title="#ffaf5f" |215 | style="color:#000000;background:#ffaf87;" title="#ffaf87" |216 | style="color:#000000;background:#ffafaf;" title="#ffafaf" |217 | style="color:#000000;background:#ffafd7;" title="#ffafd7" |218 | style="color:#000000;background:#ffafff;" title="#ffafff" |219 | style="color:#000000;background:#ffd700;" title="#ffd700" |220 | style="color:#000000;background:#ffd75f;" title="#ffd75f" |221 | style="color:#000000;background:#ffd787;" title="#ffd787" |222 | style="color:#000000;background:#ffd7af;" title="#ffd7af" |223 | style="color:#000000;background:#ffd7d7;" title="#ffd7d7" |224 | style="color:#000000;background:#ffd7ff;" title="#ffd7ff" |225 | style="color:#000000;background:#ffff00;" title="#ffff00" |226 | style="color:#000000;background:#ffff5f;" title="#ffff5f" |227 | style="color:#000000;background:#ffff87;" title="#ffff87" |228 | style="color:#000000;background:#ffffaf;" title="#ffffaf" |229 | style="color:#000000;background:#ffffd7;" title="#ffffd7" |230 | style="color:#000000;background:#ffffff;" title="#ffffff" |231 |- | colspan="36" | |} To calculate the RGB values of the colors in the table above, the following Python script can be used: print a list of the 256-color red/green/blue values used by xterm.[src] reference: https://github.com/ThomasDickey/ncurses-snapshots/blob/master/test/xterm-16color.dat https://github.com/ThomasDickey/xterm-snapshots/blob/master/XTerm-col.ad https://github.com/ThomasDickey/xterm-snapshots/blob/master/256colres.pl print("colors 0-15 correspond to the ANSI and aixterm naming") for code in range(0, 16): if code > 8: level = 255 elif code == 7: level = 229 else: level = 205 r = 127 if code == 8 else level if (code & 1) != 0 else 92 if code == 12 else 0 g = 127 if code == 8 else level if (code & 2) != 0 else 92 if code == 12 else 0 b = 127 if code == 8 else 238 if code == 4 else level if (code & 4) != 0 else 0 print(f"{code:3d}: {r:02X} {g:02X} {b:02X}") print("colors 16-231 are a 6x6x6 color cube") for red in range(0, 6): for green in range(0, 6): for blue in range(0, 6): code = 16 + (red * 36) + (green * 6) + blue r = red * 40 + 55 if red != 0 else 0 g = green * 40 + 55 if green != 0 else 0 b = blue * 40 + 55 if blue != 0 else 0 print(f"{code:3d}: {r:02X} {g:02X} {b:02X}") print("colors 232-255 are a grayscale ramp, intentionally leaving out black and white") for gray in range(0, 24): level = gray * 10 + 8 code = 232 + gray print(f"{code:3d}: {level:02X} {level:02X} {level:02X}") There has also been a similar but incompatible 88-color encoding using the same escape sequence, seen in and .[src] It uses a 4×4×4 color cube.[src] == Operating System Command sequences == Most Operating System Command sequences were defined by Xterm, but many are also supported by other terminal emulators.[src] For historical reasons, Xterm can end the command with (0x07) as well as the standard (0x9C or 0x1B 0x5C).[src] For example, Xterm allows the icon name and window title to be set by .[src] A non-xterm extension is the hyperlink, from 2017, used by VTE, iTerm2, and mintty, among others.[src] The Linux console uses to change the palette, which, if hard-coded into an application, may hang other terminals.[src] However, appending will be ignored by Linux and form a proper, ignorable sequence for other terminals.[src] make 2>&1 | sed -e 's/.*\bWARN.*/ \x1b[7m & \x1b[0m /i' -e 's/.*\bERR.*/ \x1b[93;41m & \x1b[0m /i' The following Bash function flashes the terminal (by alternately sending reverse and normal video mode codes) until the user presses a key.[src] It can be used to alert a programmer when a lengthy command terminates, such as with .[src] {{codett|2=bash|1=flasher () { while true; do printf}} '\e[?5h' '\e[?5l' {{codett|2=bash|1=; read -s -n1 -t1 && break; done; } }} The following command will reset the console, similar to the command on modern Linux systems; however it should work even on older Linux systems and on other (non-Linux) UNIX variants.[src] include int main(void) { int row, col, n; for (row = 0; row 109) break; printf("\033[%dm %3d\033[m", n, n); } printf("\n"); } return 0; } xterm replies CSI row ; column R if asked for cursor position and CSI 1 ; modifiers R if the key is pressed with modifiers, which collide in the case of row == 1 .[src] This can be avoided by using the ?[src] private modifier as CSI ?[src] 6 n , which will be reflected in the response as CSI ?[src] row ; column R .[src] many terminals prepend ESC to any character that is typed with the alt key down.[src] This creates ambiguity for uppercase letters and symbols @[\]^_ , which would form C1 codes.[src] Konsole generates SS3 modifiers char when are pressed with modifiers.[src] Some terminals, including iTerm2 and kitty, support reporting additional keys via an enhanced CSI u mode.[src] ITU-T Rec.[src] T.416 (03/93) Information technology – Open Document Architecture (ODA) and interchange format: Character content architectures[src]

54 sentences · 54 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"ANSI escape code." encyclopegia.org, 2026, https://encyclopegia.org/wiki/ansi-escape-code. Accessed 25 November 2026.

Chicago

"ANSI escape code." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/ansi-escape-code.

APA

encyclopegia.org. (2026). ANSI escape code. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/ansi-escape-code

Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Advanced Crew Escape Suit

stub · references available

criminal code

stub · references available

The Da Vinci Code

stub · references available

The Great Escape

stub · references available

Z code

stub · references available

genetic code

stub · references available

Code:Breaker

stub · references available

IATA airport code

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1378451808 · 0.5 · snapshot enwiki-001378451808

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.