ANSI Color Codes Reference
Complete reference for ANSI escape codes — 16 standard colors, 256-color palette, RGB true color, and text styles.
Terminal Emulator Sandbox
Text styles
Select a row to copy the escape sequence.
Standard 16 colors — foreground / background
256-color mode
Use \e[38;5;<n>m for foreground and \e[48;5;<n>m for background, where n is 0–255.
0–15
Standard 16 colors (same as above)
16–231
6×6×6 RGB color cube
232–255
24 grayscale shades (dark → light)
Click any swatch to copy its foreground escape sequence.
True color (24-bit RGB)
Use \e[38;2;R;G;Bm for foreground and \e[48;2;R;G;Bm for background.
How ANSI escape codes work
ANSI escape codes are byte sequences recognized by most terminals (Linux, macOS, Windows Terminal) to format output — colours, bold, italic, underline. The format is ESC[<code>m where ESC is the escape character (byte 0x1B, written as \e in bash/zsh or \033 in C). Always reset with \e[0m after coloured output to avoid leaking styles.
The codes on this page are the same ones you use to colour bash and zsh output. To encode binary data, use the Base64 Encoder.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Finding the escape sequence for a colour in terminal output.
- Looking up a 256-colour or true-colour code.
- Getting the reset sequence to close a style.
- Checking which style codes a terminal supports.
- Copying a sequence to paste into a script.
Frequently Asked Questions
- What is the difference between the 16-colour, 256-colour and true-colour sets?
- The original 16 are named and remapped by the terminal theme, so they follow the user's palette. The 256-colour cube and 24-bit true colour specify exact values — precise, and they ignore the theme entirely.
- Why do my colours look different in another terminal?
- Because the basic 16 are defined by the emulator, not the standard — one terminal's "red" is another's crimson. Anything that must look identical everywhere has to use true-colour escapes.
- How do I reset formatting?
- `ESC[0m` clears everything. Failing to emit it is why a crashed program can leave the shell prompt permanently coloured — the terminal has no idea the program ended.
- Should output be coloured when piped to a file?
- No. Escape codes become literal junk in a log or a pipe, so well-behaved tools check whether stdout is a TTY and disable colour when it is not — the convention `--color=auto` describes.
- How do I detect support before emitting codes?
- Check the `TERM` variable and whether stdout is a terminal, and honour `NO_COLOR` if it is set. That last one is a widely-respected convention for users who want plain output everywhere.
Common errors and gotchas
- Forgetting the reset sequence, which leaves the terminal styled after the program exits.
- Assuming true colour is supported, which many terminals and CI environments do not.
- Emitting colour codes when output is piped or redirected, which then appear as garbage.
- Relying on colour alone to convey meaning, which fails for colour-blind users and for logs.
- Using bright variants and assuming they render as bold, which differs by terminal.