ANSI Color Code Generator
Build ANSI escape sequences for colored terminal output with a live preview. Pick foreground and background from the 16 standard ANSI colors, add attributes like bold, underline or italic, enter sample text, and get copy-ready sequences in bash (\033[), Python, Node.js, and raw numeric form. No more guessing SGR codes.
How to use the ANSI Color Code Generator
Select a foreground (text) color and optionally a background color from the 16 standard ANSI colors. Tick any style attributes: Bold makes text heavier, Dim reduces intensity, Italic is slanted (support varies), Underline adds an underline, Blink flashes the text (support varies by terminal), Reverse swaps foreground and background colors.
The live preview box shows how the styled text will appear in a dark terminal. Enter your own sample text in the text field to preview a realistic message.
Below the preview, the generator outputs:
- Bash (
\033[): embed directly inecho -eorprintf - \e[ notation: shorter form, works in most shells
- \x1b[ notation: works in Python strings without extra flags
- Python: ready to use with
print() - Node.js: ready to use with
process.stdout.write()orconsole.log() - Raw SGR codes: just the numeric codes separated by semicolons
The reset sequence \033[0m is always appended to return the terminal to its default state after the text.
About ANSI Escape Codes
ANSI escape codes are standardised sequences of bytes that terminals interpret as control commands rather than printable characters. They originate from the ANSI X3.64 standard (1979) and the VT100 terminal. The most common type is the SGR (Select Graphic Rendition) sequence: ESC[nm where n is a semicolon-separated list of attribute codes. ESC is ASCII 27 (0x1B), written as \033 in octal, \x1b in hex, or \e in some contexts.
The 16 standard ANSI colors correspond to SGR codes 30-37 for normal foreground, 40-47 for background, and 90-97 / 100-107 for "bright" (high-intensity) variants. Exact color appearance depends on the terminal emulator's theme — a terminal showing "red" (31) as orange or dark red is within spec. For precise colors, use 256-color mode (38;5;N) or 24-bit truecolor (38;2;R;G;B).
Attribute codes include 1 (bold/bright), 2 (dim/faint), 3 (italic — not widely supported), 4 (underline), 5 (slow blink — many terminals ignore this), 7 (reverse video — swap fg/bg), and 9 (strikethrough). Reset code 0 clears all attributes. Every styled string should end with \033[0m to prevent color bleeding into subsequent terminal output.
Common use cases
- CLI tool output coloring — highlight errors in red, warnings in yellow and success messages in green to improve readability of terminal output.
- Shell script prompts — color the PS1 prompt to distinguish production from staging environments or different Git branches.
- Log formatting — add severity-level colors to structured log output in long-running processes to make scanning logs faster.
- Test suite output — color pass/fail indicators to make failing tests immediately visible in CI terminal output.
- Interactive CLI menus — bold selected items and dim inactive options in interactive prompts written in Python or Node.