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)

CodeEffectNotes
0Reset / NormalAll attributes off. Equivalent to cls constant.
1Bold (increased intensity)
2Dim (decreased intensity)Not widely supported on Windows Terminal.
3Italic
4Underline
5Slow blinkLess than 150 blinks per minute. Rarely supported.
6Rapid blinkMore than 150 blinks per minute. Very rarely supported.
7Reverse video (swap fg / bg)
8Conceal (hidden)Not widely supported. Text is invisible but selectable.
9Strikethrough (crossed-out)
10Default (primary) font
11–19Alternative fonts 1–9Select alternative font n−10. Rarely supported.
20Fraktur (Gothic)Hardly ever supported.
21Doubly underlined; or Bold offBehavior varies by terminal.
22Normal intensityNeither bold nor dim.
23Not italic, not Fraktur
24Not underlined
25Not blinking
26Proportional spacingITU T.61 / T.416. Not widely supported.
27Not reversed
28Reveal (not concealed)
29Not crossed out
30–37Set foreground color (4-bit standard)30=Black, 31=Red, 32=Green, 33=Yellow, 34=Blue, 35=Magenta, 36=Cyan, 37=White
38Set foreground color (extended)Next args: 5;n for 8-bit or 2;r;g;b for 24-bit.
39Default foreground color
40–47Set background color (4-bit standard)40=Black, 41=Red, 42=Green, 43=Yellow, 44=Blue, 45=Magenta, 46=Cyan, 47=White
48Set background color (extended)Next args: 5;n for 8-bit or 2;r;g;b for 24-bit.
49Default background color
50Disable proportional spacing
51FramedRarely supported.
52EncircledRarely supported.
53Overlined
54Not framed, not encircled
55Not overlined
56–57(Reserved)
58Set underline colorNext args: 5;n for 8-bit or 2;r;g;b for 24-bit. Kitty, iTerm2, mintty.
59Default underline color
60Ideogram underline or right side lineRarely supported.
61Ideogram double underline or double right side line
62Ideogram overline or left side line
63Ideogram double overline or double left side line
64Ideogram stress marking
65No ideogram attributes
66–72(Reserved)
73Superscriptmintty only.
74Subscriptmintty only.
75Not superscript, not subscript
76–89(Reserved)
90–97Set bright foreground color90=BrightBlack (Gray), 91=BrightRed, 92=BrightGreen, 93=BrightYellow, 94=BrightBlue, 95=BrightMagenta, 96=BrightCyan, 97=BrightWhite
98–99(Reserved)
100–107Set bright background color100=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:

0
ResetClears all styles
1
BoldIncreased intensity
2
DimDecreased intensity
3
ItalicItalic text
4
UnderlineUnderlined text
7
ReverseSwap fg/bg
9
StrikethroughCrossed-out text
22
Normal intensityReset bold/dim
23
No italicReset italic
24
No underlineReset underline

Using 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!