Skip to content

SGR — Select Graphic Rendition

SequenceCSI <p1> ; <p2> ; … m
Bytes0x1B 0x5B <params> 0x6D
CategoryCSI
MnemonicSGR
Otty support✓ Implemented (full standard + extended underlines + RGB)

Description

Sets graphic rendition for subsequent characters — foreground / background color, weight, italic, underline, strike-through, etc. Parameters are 1+ numeric codes separated by ; (or : for sub-parameters); multiple codes apply in order.

CSI m (no parameters) and CSI 0 m both reset all attributes.

Common parameters

ParamEffect
0Reset
1Bold
2Dim
3Italic
4Underline
5Blink
7Reverse video
8Conceal
9Strike-through
21Double underline
22Reset bold/dim
23Reset italic
24Reset underline
3037Foreground ANSI 0-7
38;5;<n>Foreground 256-color
38;2;<r>;<g>;<b>Foreground 24-bit
39Default foreground
4047Background ANSI 0-7
48;5;<n>Background 256-color
48;2;<r>;<g>;<b>Background 24-bit
49Default background
9097Foreground bright 0-7
100107Background bright 0-7

Extended underlines

Using : sub-parameters (the kitty / iTerm2 / WezTerm convention). All five styles render in Otty:

Sub-paramStyleOtty rendering
4:0Noneclears underline
4:1Single2 px underline (also via plain \e[4m)
4:2Doubletwo stacked 2 px lines (use 4:2, not \e[21m — under ECMA-48, 21 resets bold)
4:3Curly (undercurl)square-wave wavy line, fg or SGR 58 colored
4:4Dottedrepeating dot pattern
4:5Dashedrepeating short-dash pattern
58:5:<n> or 58:2::<r>:<g>:<b>Underline color (independent of text color)applied to single / double / curly / dotted / dashed
59Reset underline colorback to text color

Note: kitty's writers usually emit the colon form 58:2::R:G:B (the empty colorspace slot before the RGB triple); the semicolon form 58;2;R;G;B is also accepted.

Example

bash
# Bold red text
printf '\e[1;31mERROR\e[0m\n'

# 24-bit color
printf '\e[38;2;127;90;240mpurple\e[0m\n'

# Curly red underline beneath default-colored text — the SGR 58 form
# nvim's LSP uses for error squiggles
printf '\e[4:3;58:2::255:100:100mtypo\e[0m\n'

# Dashed green underline (warnings)
printf '\e[4:5;58:2::120:255:120mTODO\e[0m\n'

# Try every style at once:
otty features try styles

Try it

  • otty features try styles — bold / italic / underline / strike / reverse / blink sampler.
  • otty features try true-color — 24-bit gradient strip across bg and fg.
  • otty features try text-style — ASCII × CJK trait stress (catches font-cascade slips).
  • otty features try font-blending — same line on dark / medium / light bg for comparing font-blending modes.
  • otty features try change-color — interactive OSC 10/11/12/17/19 + XTPUSHCOLORS picker.

Notes

  • Parameter 1 (bold) renders in the bright palette when bold-is-bright = on (config). Off by default.
  • Otty caps SGR parsing at 256 parameters per sequence; very long chains beyond that are truncated.
  • Some terminals interpret 1 as a "bright" hint instead of bold weight; Otty applies real weight from the font.

Otty