ANSI color codes are Select Graphic Rendition (SGR) escape sequences that ask a terminal emulator to switch between eight base and eight bright palette slots for foreground and background text. The codes themselves are decimal numbers, not literal colors: 30 selects the black foreground slot, 91 selects the bright red foreground slot, and 44 selects the blue background slot. A working sequence begins with the ESC control byte, an opening square bracket, one or more semicolon-separated SGR parameters, and the letter m. After the formatted text, a reset of ESC[0m returns the terminal to its default rendition so the next line is not accidentally painted. Because the numbers describe palette positions rather than RGB values, the visual result depends on the user's terminal theme, color profile, and accessibility settings. The ANSI Color Codes Generator produces both the visible escaped form and the raw control bytes for these sequences so you can paste them into source strings, fixtures, and terminal-aware tools with confidence.

The Structure of an SGR Escape Sequence
Every SGR sequence follows the same four-part shape: an escape byte (0x1B), an opening square bracket, a list of decimal parameters separated by semicolons, and the terminating letter m. The terminal interprets the numbers in order. Style parameters are usually placed before color parameters, although the order between style codes and color codes is not strictly enforced by every consumer. The three style parameters the generator supports are 1 for bold, 3 for italic, and 4 for underline, although the current interface exposes bold and underline. Color parameters are split into two groups: base codes run from 30 to 37 for foreground and 40 to 47 for background, while the widely implemented xterm-compatible bright extensions run from 90 to 97 for foreground and 100 to 107 for background.
The reset sequence ESC[0m is appended whenever the generator builds a prefix. That trailing reset is a guardrail rather than a guarantee: a destination application may interpret the stream differently, may apply its own reset on exit, or may be running in a context where the byte sequence is filtered. Always treat ESC[0m as the closing of the formatted region and not as a promise that downstream output will be plain. ECMA-48 defines SGR and the base rendition controls, and the xterm control sequences documentation cross-checks the bright mappings that most modern terminals use.
The 16 SGR Color Code Table
Each palette slot has a fixed SGR number. The table below lists the eight base colors and their eight bright counterparts for both foreground and background, in the order most terminal emulators expose them.
| Color name | Base foreground | Base background | Bright foreground | Bright background |
|---|---|---|---|---|
| Black | 30 | 40 | 90 | 100 |
| Red | 31 | 41 | 91 | 101 |
| Green | 32 | 42 | 92 | 102 |
| Yellow | 33 | 43 | 93 | 103 |
| Blue | 34 | 44 | 94 | 104 |
| Magenta | 35 | 45 | 95 | 105 |
| Cyan | 36 | 46 | 96 | 106 |
| White | 37 | 47 | 97 | 107 |
These are the 16 named slots the generator stores. The numbers do not specify red, green, or blue intensities; they ask the terminal to address a slot, and the user's terminal configuration decides what that slot looks like. When you search the 16-color code reference inside the tool, the color name describes the slot, not a guaranteed RGB value.
How to Build an ANSI Color Sequence in Your Browser
- Open the ANSI Color Codes Generator and enter the text you want formatted in the terminal.
- Choose an optional foreground, an optional background, and add bold or underline only if you need them; unsupported style and color numbers are rejected, so unexpected values are not silently emitted.
- Generate the sequence and inspect both the visible escaped representation, where the escape byte is written as \x1b, and the raw SGR parameters so you can confirm the prefix, the text, and the trailing reset before you copy anything.
- Copy the raw sequence only into a trusted terminal-aware context such as a source string, a fixture, or a debugging workflow, then paste it into the real terminal and verify the visible behavior, including that the reset at the end actually returns the next output to plain text.
A concrete prefix for bright red foreground, blue background, bold, and underline is the parameter list 1;4;91;44. The generated stream therefore looks like ESC[1;4;91;44m followed by the text, then ESC[0m to close the region. The visible escaped representation writes the leading byte as the four characters \x1b so the page itself never changes appearance while you review the sequence.
Why the Same Code Can Look Different in Another Terminal
SGR color numbers are slot selectors, not paint recipes. Terminal emulators, color themes, user profiles, accessibility settings, multiplexers, remote environments, and individual applications can remap the slot to any RGB triple they want. The bright 90 through 107 range is implemented in xterm-compatible emulators, and ECMA-48 only standardizes the base 30 through 47 range; the bright mappings are a common extension rather than a formal part of the standard. The generator cannot know what your users will see, which is why the page deliberately does not display a fake color preview that would imply one universal terminal palette.
Bold is similarly flexible. Some terminals interpret parameter 1 as a heavier font weight, others select an increased-intensity color, and a few older terminals use bold to access the bright palette. Underline shape and color also vary across emulators. Plan a fallback path for users who configure their terminal to ignore color, follow the NO_COLOR convention, or redirect output to a non-interactive sink where the bytes are not interpreted at all.
Handling Escape Bytes Safely in Logs and Terminals
Raw escape bytes are control data, not printable characters. Pasting the copied sequence into a terminal command line, log file, issue tracker, chat message, or source file produces invisible control behavior rather than readable text. Logs that contain untrusted control characters can hide text, forge visual lines, create misleading links, or disrupt terminal state for the next reader. Sanitize untrusted data before printing it to an interactive terminal and provide a plain-text logging path where control sequences are removed or visibly escaped.
The generator's visible escaped form is built for exactly this review step. When the escape byte is rendered as \x1b, the rest of the string stays searchable and copy-pasteable without accidentally triggering terminal behavior. Use the visible form for documentation, README examples, and code comments; use the raw form only when the destination is known to interpret SGR correctly.
Limits of the Browser Generator and Real Terminal Testing
The page has no terminal emulator, so it cannot determine whether a destination supports ECMA-48, xterm extensions, Windows virtual terminal processing, NO_COLOR conventions, or redirected noninteractive output. All text, choices, generated bytes, search terms, and clipboard operations remain in the browser; nothing is uploaded or executed in a shell. The generator supports three style parameters only: bold at 1, italic at 3 in logic compatibility, and underline at 4, although the current interface exposes bold and underline. Unsupported style and color numbers are rejected, so the prefix you copy will always be a valid SGR sequence even if it does not match the destination's expectations.
For reliable use, generate the smallest necessary set of parameters, inspect the visible representation, copy only into a trusted context, reset formatting at the end of every region, and verify the behavior in the real terminal themes and output modes your users actually run. Eight external fixtures lock the base foreground and background pairs, and the tests also enforce 16 unique code rows, one bright filter result, and an exact multi-style raw and escaped sequence, so the output you copy from the page matches what the reference suite expects.
For a deeper conceptual walkthrough of the SGR mechanism and how palette slots map to color themes, the developer reference on ANSI colors covers the underlying specification in more detail.
Related reading: How to Use an ASCII Table: Lookup, Search, and Copy Codes.