Skip to main content
ansicode

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[\x1b[4m
\\033[\033[4m
\\e[\e[4m
ESC [ESC [ 4 m
hex1b 5b 34 6d

Description

Single underline. Kitty introduced extensions for styled underlines: `\x1b[4:1m` (single), `4:2m` (double), `4:3m` (curly), `4:4m` (dotted), `4:5m` (dashed); colored underline via `\x1b[58;5;Nm` or `\x1b[58;2;R;G;Bm`. Disable underline with `\x1b[24m`. The double-underline pattern `\x1b[21m` is recognized by xterm and most modern terminals (originally SGR 21 meant 'doubly underlined' in ECMA-48; some terminals interpret it as 'bold off').

Spec citation: ECMA-48 §8.3.117 (SGR parameter 4); kitty underline extensions

Examples

bash
printf '\033[4munderline\033[24m back\033[0m\n'
python
print('\x1b[4munderline\x1b[0m')
go
fmt.Print("\x1b[4munderline\x1b[0m")
javascript
console.log('\x1b[4munderline\x1b[0m')
c
printf("\x1b[4munderline\x1b[0m\n");

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
no
GNU screen
no

Related sequences

In the family cookbook

SGR cookbook · 6. SGR colon sub-params — the standards-correct form