Font Effects (SGR Parameters)
ANSI terminals use Select Graphic Rendition (SGR) parameters to control text appearance. These are sent as part of an escape sequence: \x1b[<code>m (or ESC [ <code> m).
The table below lists every standardised SGR code from 0 to 107, its effect, and practical notes on terminal compatibility.
How It Works
When you write \x1b[1m the terminal sees ESC [ (the "Control Sequence Introducer") followed by the number 1 and the letter m. The number selects the graphic rendition — in this case, Bold. Multiple codes can be combined with semicolons: \x1b[1;3;31m = bold + italic + red.
// General form:
ESC [ <code> m
// Multiple codes:
ESC [ <code1> ; <code2> ; ... m
// Example: bold + italic + red foreground
"\x1b[1;3;31m"
SGR Code Reference (0–107)
| Code | Effect | Notes |
|---|---|---|
| 0 | Reset / Normal | All attributes off. Equivalent to cls constant. |
| 1 | Bold (increased intensity) | — |
| 2 | Dim (decreased intensity) | Not widely supported on Windows Terminal. |
| 3 | Italic | — |
| 4 | Underline | — |
| 5 | Slow blink | Less than 150 blinks per minute. Rarely supported. |
| 6 | Rapid blink | More than 150 blinks per minute. Very rarely supported. |
| 7 | Reverse video (swap fg / bg) | — |
| 8 | Conceal (hidden) | Not widely supported. Text is invisible but selectable. |
| 9 | Strikethrough (crossed-out) | — |
| 10 | Default (primary) font | — |
| 11–19 | Alternative fonts 1–9 | Select alternative font n−10. Rarely supported. |
| 20 | Fraktur (Gothic) | Hardly ever supported. |
| 21 | Doubly underlined; or Bold off | Behavior varies by terminal. |
| 22 | Normal intensity | Neither bold nor dim. |
| 23 | Not italic, not Fraktur | — |
| 24 | Not underlined | — |
| 25 | Not blinking | — |
| 26 | Proportional spacing | ITU T.61 / T.416. Not widely supported. |
| 27 | Not reversed | — |
| 28 | Reveal (not concealed) | — |
| 29 | Not crossed out | — |
| 30–37 | Set foreground color (4-bit standard) | 30=Black, 31=Red, 32=Green, 33=Yellow, 34=Blue, 35=Magenta, 36=Cyan, 37=White |
| 38 | Set foreground color (extended) | Next args: 5;n for 8-bit or 2;r;g;b for 24-bit. |
| 39 | Default foreground color | — |
| 40–47 | Set background color (4-bit standard) | 40=Black, 41=Red, 42=Green, 43=Yellow, 44=Blue, 45=Magenta, 46=Cyan, 47=White |
| 48 | Set background color (extended) | Next args: 5;n for 8-bit or 2;r;g;b for 24-bit. |
| 49 | Default background color | — |
| 50 | Disable proportional spacing | — |
| 51 | Framed | Rarely supported. |
| 52 | Encircled | Rarely supported. |
| 53 | Overlined | — |
| 54 | Not framed, not encircled | — |
| 55 | Not overlined | — |
| 56–57 | (Reserved) | — |
| 58 | Set underline color | Next args: 5;n for 8-bit or 2;r;g;b for 24-bit. Kitty, iTerm2, mintty. |
| 59 | Default underline color | — |
| 60 | Ideogram underline or right side line | Rarely supported. |
| 61 | Ideogram double underline or double right side line | — |
| 62 | Ideogram overline or left side line | — |
| 63 | Ideogram double overline or double left side line | — |
| 64 | Ideogram stress marking | — |
| 65 | No ideogram attributes | — |
| 66–72 | (Reserved) | — |
| 73 | Superscript | mintty only. |
| 74 | Subscript | mintty only. |
| 75 | Not superscript, not subscript | — |
| 76–89 | (Reserved) | — |
| 90–97 | Set bright foreground color | 90=BrightBlack (Gray), 91=BrightRed, 92=BrightGreen, 93=BrightYellow, 94=BrightBlue, 95=BrightMagenta, 96=BrightCyan, 97=BrightWhite |
| 98–99 | (Reserved) | — |
| 100–107 | Set bright background color | 100=BrightBlack (Gray), 101=BrightRed, 102=BrightGreen, 103=BrightYellow, 104=BrightBlue, 105=BrightMagenta, 106=BrightCyan, 107=BrightWhite |
Commonly Used Codes
Most terminals reliably support a small subset. Here are the ones you'll use most often:
0123479222324Using with s()
You don't need to memorize these codes — the s() function and StyleOptions handle the common ones for you:
// StyleOptions styles → SGR codes
"bold" → \x1b[1m (code 1)
"italic" → \x1b[3m (code 3)
"underline" → \x1b[4m (code 4)
"strikethrough" → \x1b[9m (code 9)
// Colors → SGR codes 30–37 (fg), 40–47 (bg)
// Extended → SGR code 38;5;n (8-bit) or 38;2;r;g;b (24-bit)
// Reset → SGR code 0 (appended unless endless: true)
Compatibility Notes
Bold vs Bright: In some terminals, code 1 (bold) also brightens the foreground color. This is legacy behavior — modern terminals generally treat bold and color independently.
Blink (5, 6): Almost universally ignored by modern terminals. Never rely on blink being visible.
Dim (2): Supported in most Linux terminals (GNOME Terminal, Konsole, kitty) but may be ignored in older versions of Windows Terminal. The constant DIM and DIM_OFF are exported from the ansi module.
Always reset: If you apply styles manually, remember to append \x1b[0m (or use cls/RESET) to avoid style bleed into subsequent output.
Want to support this project?
If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.
Want to contribute to this project?
Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!