← Back to home

ANSI Color Codes — Escape Sequence Cheat Sheet

Last reviewed on August 23, 2026.

The escape sequences that color terminal output. Click any tile to copy the sequence. The preview cell shows roughly how a true-color terminal would render it. Three sections: the 8 base colors plus their bright variants, the full 256-color palette, and the style modifiers (bold, underline, reverse).

Format:

8 base colors (foreground)

The original ANSI palette. Codes 30–37 are foreground colors, with 0 as the reset code.

8 bright colors (foreground)

Codes 90–97. These map to lighter variants of the same hues. Some terminal themes brighten the regular colors and ignore the bright codes; others reserve the bright codes for genuinely lighter shades.

8 base colors (background)

Codes 40–47 for backgrounds. Bright backgrounds are 100–107.

Style modifiers

Codes between 1 and 9 control style. Most modern terminals support bold, dim, underline, and reverse cleanly. Italic and strikethrough are widely but not universally supported.

256-color palette

Use \x1b[38;5;Nm for foreground and \x1b[48;5;Nm for background, where N is 0–255. The first 16 are the base + bright colors above, then there is a 6×6×6 RGB cube (16–231), and finally a 24-step grayscale ramp (232–255).

24-bit "true color"

Modern terminals support 24-bit color via \x1b[38;2;R;G;Bm for foreground and \x1b[48;2;R;G;Bm for background. R, G, B are decimal 0–255. Most terminal emulators released after 2018 support this; some legacy environments (older Windows command prompt, certain CI runners) still cap at 256 colors.

For curated color values that work well in a hacker-aesthetic terminal, see the cyberpunk color palettes page — every HEX value there can drive a 24-bit ANSI sequence after splitting into R, G, B.

Anatomy of an escape sequence

An ANSI color sequence has three parts:

The empty parameter list — \x1b[0m or just \x1b[m — resets all attributes. End every styled run with a reset, or the styling carries into whatever the terminal prints next.

Worked example: a colored shell prompt

A two-color prompt that shows the user in green and the path in cyan, followed by a reset:

PS1='\[\033[32m\]\u\[\033[0m\]@\[\033[36m\]\w\[\033[0m\]\$ '

The \[ and \] markers are Bash-specific — they tell the shell that the bytes between them do not take up screen columns, so word wrapping does not get confused. Outside the prompt, you do not need them.

Printing colours in each language

The escape sequence is identical everywhere — only the way you write the ESC byte changes. Each snippet below prints red text and then resets.

Bash / sh

echo -e "\033[31mRed text\033[0m"
printf '\033[1;32m%s\033[0m\n' "Bold green"

Python

print("\033[31mRed text\033[0m")

# 24-bit colour
print("\033[38;2;0;229;255mCyan glow\033[0m")

# Reusable constants
RED, RESET = "\033[31m", "\033[0m"
print(f"{RED}error{RESET}: something went wrong")

Node.js / JavaScript

console.log('\x1b[31mRed text\x1b[0m');
console.log(`\x1b[38;5;208m256-colour orange\x1b[0m`);

C

#include <stdio.h>

int main(void) {
    printf("\033[31mRed text\033[0m\n");
    printf("\x1b[48;2;20;20;30m dark background \x1b[0m\n");
    return 0;
}

Go

fmt.Println("\033[31mRed text\033[0m")
fmt.Printf("\033[38;2;%d;%d;%dmRGB text\033[0m\n", 0, 229, 255)

Rust

println!("\x1b[31mRed text\x1b[0m");
println!("\x1b[1;4;36mBold underlined cyan\x1b[0m");

PowerShell

$e = [char]27
Write-Host "$e[31mRed text$e[0m"

# PowerShell 6+ also accepts the backtick escape
Write-Host "`e[32mGreen text`e[0m"

Java

System.out.println("\u001B[31mRed text\u001B[0m");

Do these work on Windows?

Yes, on Windows 10 build 1511 and later — but only once virtual terminal processing is enabled for the console. Windows Terminal, PowerShell 7, VS Code's terminal, and Git Bash all enable it for you. The legacy cmd.exe console host may not, in which case escape sequences print as literal garbage such as ←[31m.

Detecting colour support

Well-behaved command-line tools disable colour when their output is piped to a file or another program, because escape bytes corrupt logs and break parsers. The conventional checks:

Common mistakes

ANSI color code FAQ

What are ANSI color codes?

ANSI colour codes are escape sequences that tell a terminal how to render the text that follows. They begin with the Escape byte (0x1b) and an opening bracket, contain one or more numeric parameters, and end with the letter m — for example \x1b[31m sets red foreground text and \x1b[0m resets all attributes.

What is the ANSI code for red?

31 for red foreground text and 41 for a red background. The full sequence is \x1b[31m, written as \033[31m in Bash and Python. Bright red is 91 for foreground and 101 for background.

How do I reset ANSI colors?

Use \x1b[0m, which resets every attribute — colour, bold, underline, and reverse. Always end a styled run with it, or the styling bleeds into whatever the terminal prints next.

How do I use 256 colors in the terminal?

Use \x1b[38;5;Nm for foreground and \x1b[48;5;Nm for background, where N is 0–255. Codes 0–15 are the standard and bright colours, 16–231 form a 6×6×6 RGB cube, and 232–255 are a 24-step greyscale ramp.

How do I use 24-bit RGB colors in the terminal?

Use \x1b[38;2;R;G;Bm for foreground and \x1b[48;2;R;G;Bm for background, with decimal values 0–255. Most emulators released after 2018 support it; check whether COLORTERM is set to truecolor.

Do ANSI color codes work on Windows?

Yes on Windows 10 build 1511 and later, once virtual terminal processing is enabled for the console. Windows Terminal, PowerShell 7, VS Code's terminal, and Git Bash enable it automatically. In legacy cmd.exe the sequences may print as literal text instead.

Why do I see characters like ←[31m instead of colour?

The terminal is not interpreting escape sequences. On Windows that means virtual terminal processing is off; elsewhere it usually means output was piped to a file or another program rather than a terminal, or TERM is set to dumb.

Where this fits with the other tools on the site

For overall palette choices, the cyberpunk color palettes page has the HEX values; convert them to R;G;B for 24-bit ANSI. For the box-drawing characters that pair well with colored output, see the Unicode symbol reference or the box-drawing tool. To wrap a colored prompt around a banner, generate one with the ASCII banner generator and inject the ANSI escapes around it.