CSS Reference ยท Typography
The text-underline-position property
Reference for the CSS text-underline-position property: where an underline sits relative to the text, under and from-font values, and support notes.
The text-underline-position property controls where an underline is placed relative to the text. By default the browser puts it just below the alphabetic baseline. With under the line moves down below the lowest part of the text, which is useful for mathematical subscripts and certain scripts. With from-font it follows the position stored in the font.
For most pages you will use text-underline-offset instead, which gives precise control. Treat this property as a fine-tuning option.
.formula { text-decoration: underline; text-underline-position: under; }
Try it
With auto the line sits near the baseline and crosses the tails of "g", "y" and "p". With under it is placed below them. Depending on the browser and font, the difference can be small, so test on your target platforms.
Syntax
text-underline-position: auto | [ from-font | under ] || [ left | right ];
- Initial value:
auto - Applies to: all elements; also
::first-letterand::first-line - Inherited: yes
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
The browser decides, normally near the alphabetic baseline. |
from-font |
Uses the underline position from the font's metrics, if available; otherwise it acts like auto. |
under |
Places the line below the lowest part of the text content of the element. |
left / right |
In vertical writing modes, places the line on the left or right side. They only matter for vertical text. |
Usage notes
- Browser differences. Support for keywords varies between browsers, and
leftandrightare the least supported. Check a compatibility table before depending on any value other thanauto. - Prefer an offset.
text-underline-offsetis widely supported and behaves the same way for any text, so use it for design work. - Inherited. A value on a container applies to underlined text inside.
- Needs an underline. It has no effect on overlines or line-throughs, and no effect when
text-decoration-linedoes not includeunderline. - Vertical text. For Japanese or Chinese vertical text,
leftandrightchoose the side of the line; use them withwriting-mode: vertical-rl. - Combining. When both are set,
text-underline-offsetis applied relative to the position chosen here.
Browser support
auto is supported everywhere. Other keywords have uneven support across browsers, so check a compatibility table before using them.
Related
text-underline-offsetโ distance of the underlinetext-decorationโ the shorthandwriting-modeโ vertical text- Lesson: Styling Text