Guide
ANSI escape sequences and ASCII control characters explained
Terminals show colour and formatting because programs print invisible control characters among the text. The most common are ANSI escape sequences, which start with the ESC character and tell the terminal to change colour, move the cursor or clear the screen. Seeing [31m or ^[[0m scattered through a log file means those sequences were captured without a terminal to interpret them. This page builds sequences, previews them and explains the control characters behind them.
What an escape sequence is
An escape sequence begins with the ESC character, byte 27 or 0x1B, followed by [ and a list of numbers separated by semicolons, and ends with a letter that names the command. The letter m means “select graphic rendition” (SGR): \x1b[1;31m switches to bold red, and \x1b[0m resets everything. The standard behind them is ECMA-48, and xterm added the extensions most terminals share today.
Colours: 16, 256 and true colour
Codes 30 to 37 select the eight standard foreground colours and 90 to 97 the bright ones; 40 to 47 and 100 to 107 do the same for backgrounds. For more colours, 38;5;n picks from a 256-colour palette (16 basic, a 6×6×6 colour cube and 24 greys), and 38;2;r;g;b gives any 24-bit colour. Use 48 instead of 38 for backgrounds. Only the first 16 depend on the terminal’s theme.
Writing them in your language
The colour builder shows the same sequence for four environments. In Bash, printf '\x1b[1;31m%s\x1b[0m\n' "text" is portable, while echo needs the -e option. Node uses console.log('\x1b[1;31m%s\x1b[0m', 'text'). Python accepts "\033[1;31mtext\033[0m". PowerShell 7 writes the escape as a backtick followed by e. Always end with the reset code, or the colour leaks into whatever the shell prints next.
Control characters
Below ESC sit 32 control codes, 0 to 31, plus DEL at 127. Many survive in daily use: LF (10) ends a line on Unix, CR (13) returns the cursor, HT (9) is the tab, BEL (7) beeps, and ESC (27) starts sequences. Caret notation writes control code n as ^ followed by the letter at 64 + n, so Ctrl+C is ^C (code 3) and ESC is ^[. The table lets you search by name, number or caret form.
A worked example
The preview’s Sample prints four lines. Bold green ✔ build, yellow warning, bold red error with the file name underlined, and a line using the 256-colour code 208 for orange and true-colour 99, 102, 241 for indigo. In the preview the green is rendered as rgb(13, 188, 121) and the orange as rgb(255, 135, 0). Searching the control-code table for ^[ finds the row 27 0x1B ESC Escape ^[.
Cleaning logs
Programs usually colour output only when connected to a terminal, but CI systems and script captures often keep the codes. To strip them, remove each ESC followed by [, digits and semicolons, and a letter, for instance with sed -r "s/\x1b\[[0-9;]*[A-Za-z]//g". The preview’s “copy without codes” button does the same for pasted text.
Windows and other limits
Windows Terminal and PowerShell 7 interpret sequences by default; the legacy console window needs virtual-terminal processing enabled. The preview only renders colours and text styles. Cursor movement, screen clearing and the alternate screen are listed in the reference but not emulated.
Related tools
- Regex Tester helps refine patterns for stripping codes from logs.
- ASCII Art Generator makes banners to colour with these sequences.
- Linux Command Builder builds the sed and grep commands for log cleanup.
- Invisible Character Detector reveals other hidden characters in text.
Checked against the current version of the ANSI Escape Codes on .

