The CSS text-underline-position property controls the **exact placement of underlines** relative to text. It is especially useful for improving readability, fixing overlaps with descenders (like g, j, p, q), and creating more polished typography.
Note
β Important for non-Latin scripts (Japanese, Chinese)
β Helps prevent underlines touching descenders
π¦ Syntax
Syntax
text-underline-position: auto | from-font | under | left | right;
/* Example */
text-underline-position: under;| Value | Description |
|---|---|
| auto | Browser default underline position |
| from-font | Use underline metrics from the font (most accurate) |
| under | Moves underline below descenders to avoid collision |
| left | Underlines positioned for vertical text (rare) |
| right | Underlines positioned for vertical text (rare) |
π¨ 1. Basic Usage
Basic example
p {
text-decoration: underline;
text-underline-position: under;
}Moves underline below characters like g/j/p/q to improve readability.
π¨ 2. Using from-font (Recommended)
from-font
p {
text-decoration: underline;
text-underline-position: from-font;
}Uses the fontβs built-in underline metrics β most accurate for premium typography.
π¨ 3. Default Behavior
auto
p {
text-decoration: underline;
text-underline-position: auto;
}Browser decides underline placement (may overlap descenders).
π¨ 4. Example Showing Descender Collision Fix
descenders
.text-auto {
text-decoration: underline;
text-underline-position: auto; /* may collide */
}
.text-under {
text-decoration: underline;
text-underline-position: under; /* improved */
}under prevents underlines from touching letters like:g, j, p, q, y.
π¨ 5. Vertical Writing Modes (Left & Right)
vertical text
.vertical {
writing-mode: vertical-rl;
text-decoration: underline;
text-underline-position: right;
}Underlines become side-lines in vertical text.right or left controls which side.
π§ͺ Real-World Use Cases
1οΈβ£ Clean Underlines in UI Headings
ui heading
h2 {
text-decoration: underline;
text-underline-position: under;
}2οΈβ£ Blog Paragraph Typography
blog text
p {
font-family: Georgia, serif;
text-decoration: underline;
text-underline-position: from-font;
}3οΈβ£ Japanese Vertical Text
japanese text
.jp {
writing-mode: vertical-rl;
text-decoration: underline;
text-underline-position: right;
}β οΈ Common Mistakes
- β Expecting it to work without text-decoration: underline
- β Using under for vertical text (use left/right instead)
- β Assuming all fonts support from-font
- β Forgetting script-specific behavior (Asian scripts differ)
Note
π₯ Summary
text-underline-position gives fine control over underline placement, improving readability and aesthetics especially in long-form reading and premium typography.
- auto β browser default
- under β best for readability
- from-font β most accurate for good fonts
- left/right β vertical text