ANSI Color Code Generator creates terminal escape sequences for colorized CLI output. Select foreground and background colors from the 8 standard, 16 extended, or 256 color palettes — or enter a 24-bit RGB value for true color terminals — and get the ANSI escape code ready to paste into shell scripts, Python, Node.js, or any language that outputs to a terminal.
ANSI escape codes are sequences of characters that control terminal formatting. The format is: \033[{code}m (or \x1b[{code}m or \e[{code}m). The code 0 resets all formatting. Codes 30-37 are standard foreground colors; 40-47 are background colors; 90-97 and 100-107 are bright variants. Code 1 is bold, 3 is italic, 4 is underline, 9 is strikethrough. For 256-color: \033[38;5;{n}m. For 24-bit RGB: \033[38;2;{r};{g};{b}m.
ANSI codes are supported in: most Linux terminals (bash, zsh, fish), macOS Terminal and iTerm2, Windows Terminal (but not cmd.exe by default), VS Code integrated terminal, and many CI/CD systems. Popular libraries that generate ANSI codes: chalk (Node.js), colorama (Python), ANSI-colors (Ruby), Spectre.Console (.NET).
Red error message in bash
Result: echo -e '\033[31mError: file not found\033[0m'
Bold green success
Result: echo -e '\033[1;32mBuild successful!\033[0m'
256-color background (color #202 = dark purple)
Result: \033[48;5;202m — wraps text in orange background
What is the difference between \033, \x1b, and \e?
They are all the same character: ESC (ASCII code 27 = 0x1b = 033 octal). \033 is the octal escape used in shell scripts with echo -e. \x1b is the hex escape used in most programming languages (Python, JavaScript, Ruby). \e is a shorthand supported by bash and some other shells but not all languages. In Python, you can use both \x1b and \033 in string literals.
How do I reset formatting at the end of a string?
Always add \033[0m at the end of a colored string. Without it, the formatting continues to the next terminal output. This causes the terminal to appear broken until the user opens a new session. Many color libraries add the reset automatically when you close a color scope. In Python with colorama: Fore.RESET + Back.RESET + Style.RESET_ALL.
Why do ANSI codes not work on Windows?
The classic Windows cmd.exe does not process ANSI escape codes by default — it prints them literally. Solutions: (1) Use Windows Terminal or Windows 11, which support ANSI natively. (2) Use the colorama Python library, which calls the Win32 Console API to translate ANSI codes. (3) Use the SetConsoleMode Windows API with ENABLE_VIRTUAL_TERMINAL_PROCESSING to enable ANSI support in older terminals.
What is the difference between 8-color, 256-color, and true color?
8-color ANSI (codes 30-37 and 40-47) gives 8 colors — the exact shades depend on terminal theme configuration. 256-color (codes 38;5;0-255) gives a fixed palette: 16 standard colors, a 6×6×6 RGB cube, and 24 grayscale steps. True color / 24-bit (codes 38;2;r;g;b) supports 16.7 million colors using full RGB values. Support: nearly universal for 8-color, common for 256-color, widely supported in modern terminals for true color.
How do I use ANSI colors in Python?
Method 1 — manual: print('\x1b[31mRed text\x1b[0m'). Method 2 — colorama: from colorama import Fore, Back, Style; print(Fore.RED + 'Red' + Style.RESET_ALL). Method 3 — rich library: from rich import print; print('[red]Red text[/red]'). The rich library also handles fallback for terminals that don't support ANSI, making it the best choice for production CLI tools.