SGR 4 — Underline
Render following text with an underline.
Byte forms
Every common string-literal form so you can paste-and-search either direction.
\x1b[4m\033[4m\e[4mESC [ 4 m1b 5b 34 6dLive preview
Rendered in your browser via the same tokeniser the decoder uses — no terminal needed.
Description
Single underline. The most universally rendered SGR attribute after color and reverse — every terminal in the support matrix above honors at least the basic single line, including the Linux console (which uses a sub-baseline dotted line on framebuffer mode) and ConPTY (partial, only when the host terminal handles the escape itself). Glyphs are underlined via a 1-pixel rule at descender height; visually it stacks fine with sgr-bold and color attributes.
Kitty introduced styled underlines as sub-parameter extensions to SGR 4, since adopted by alacritty, wezterm, ghostty, iTerm2 and recent Windows Terminal: \x1b[4:1m is an explicit single underline, \x1b[4:2m is a double rule, \x1b[4:3m is a curly / wavy line (the spell-check style — useful for highlighting errors), \x1b[4:4m is dotted, \x1b[4:5m is dashed. Pair with colored underlines via \x1b[58;5;Nm (256-color) or \x1b[58;2;R;G;Bm (truecolor), reset with \x1b[59m. Note the sub-parameter form uses : not ;; older terminals that don't understand sub-params will (per ECMA-48 quirks) treat 4:3 as a parse error and may render nothing — feature-detect via $TERM_PROGRAM / $COLORTERM, fall back to \x1b[4m plain underline. The double-rule \x1b[21m (ECMA-48's original 'doubly underlined') is recognized by xterm and most modern terminals; a few legacy terminals overload SGR 21 as 'bold off', so \x1b[4:2m is the safer way to spell 'double' on modern stacks.
Disable underline with \x1b[24m — surgical, leaves color and weight intact. The surgical close-pair is \x1b[4m…\x1b[24m. A common related pattern is clickable text in compatible terminals: combine osc-hyperlink (\x1b]8;;https://…\x1b\\link text\x1b]8;;\x1b\\) with \x1b[4;34m for the familiar blue-underlined-link look; iTerm2, ghostty, wezterm and recent gnome-terminal will render it as a true clickable link. See osc-hyperlink for the protocol details.
Spec citation: ECMA-48 §8.3.117 (SGR parameter 4); kitty underline extensions
Examples
printf '\033[4munderline\033[24m back\033[0m\n'print('\x1b[4munderline\x1b[0m')fmt.Print("\x1b[4munderline\x1b[0m")console.log('\x1b[4munderline\x1b[0m')printf("\x1b[4munderline\x1b[0m\n");Used in
Real-world tools that emit this sequence — anchors the bytes to commands you've already used.
- man pages (section headings)
- git diff --color-wordsintra-line emphasis on the changed token
- modern terminals on OSC 8 hyperlinksiTerm2, kitty, WezTerm, Windows Terminal auto-underline clickable links
- less search match
Frequently asked
Short answers to the questions developers actually search for this sequence.
- How do I draw a curly / wavy underline (the spell-check style)?
- Use the kitty styled-underline extension:
\x1b[4:3mfor wavy,\x1b[4:2mdouble,\x1b[4:4mdotted,\x1b[4:5mdashed. Combine with a coloured underline via\x1b[58;5;Nm(256-colour) or\x1b[58;2;R;G;Bm(truecolor). Supported on kitty, alacritty, wezterm, ghostty, iTerm2, and recent Windows Terminal — fall back to plain\x1b[4melsewhere. - What's the difference between
\x1b[24mand\x1b[0mwhen I want to stop underlining? \x1b[24mis the surgical underline-off: it removes the line and leaves colour, weight, italic intact.\x1b[0mresets *everything*, so any colour or bold you set alongside the underline goes too. Prefer\x1b[24minside styled passages; reserve\x1b[0mfor the end of a fully-styled chunk.
Terminal support
- xterm
- yes
- Linux console (fbcon)
- yes
- macOS Terminal.app
- yes
- iTerm2
- yes
- Windows Terminal
- yes
- cmd.exe / ConPTY
- partial
- kitty
- yes
- alacritty
- yes
- WezTerm
- yes
- Ghostty
- yes
- GNOME Terminal
- yes
- Konsole
- yes
- tmux
- yes
- GNU screen
- yes
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | yes | yes | yes | yes | partial | yes | yes | yes | yes | yes | yes | yes | yes |
Related sequences
In the family cookbook
SGR cookbook · 6. SGR colon sub-params — the standards-correct form