Skip to content
Tutorials Center
My learning

Topics

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.

CSS
.formula {
  text-decoration: underline;
  text-underline-position: under;
}

Try it

Auto vs under

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

CSS
text-underline-position: auto | [ from-font | under ] || [ left | right ];
  • Initial value: auto
  • Applies to: all elements; also ::first-letter and ::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 left and right are the least supported. Check a compatibility table before depending on any value other than auto.
  • Prefer an offset. text-underline-offset is 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-line does not include underline.
  • Vertical text. For Japanese or Chinese vertical text, left and right choose the side of the line; use them with writing-mode: vertical-rl.
  • Combining. When both are set, text-underline-offset is 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.