This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
* Some parts of this feature may have varying levels of support.
The text-underline-position CSS property specifies the position of the underline which is set using the text-decoration property's underline value.
text-underline-position: auto;
text-underline-position: under;
<section id="default-example">
<p>
<span class="transition-all" id="example-element"
>C<sub>8</sub>H<sub>10</sub>N<sub>4</sub>O<sub>2</sub></span
>
is the chemical formula for caffeine.
</p>
</section>
p {
font: 1.5em sans-serif;
}
#example-element {
text-decoration-line: underline;
}
/* Single keyword */ text-underline-position: auto; text-underline-position: under; text-underline-position: left; text-underline-position: right; /* Multiple keywords */ text-underline-position: under left; text-underline-position: right under; /* Global values */ text-underline-position: inherit; text-underline-position: initial; text-underline-position: revert; text-underline-position: revert-layer; text-underline-position: unset;
autoThe user agent uses its own algorithm to place the line at or under the alphabetic baseline.
from-fontIf the font file includes information about a preferred position, use that value. If the font file doesn't include this information, behave as if auto was set, with the browser choosing an appropriate position.
underForces the line to be set below the alphabetic baseline, at a position where it won't cross any descenders. This is useful for ensuring legibility with chemical and mathematical formulas, which make a large use of subscripts.
leftIn vertical writing-modes, this keyword forces the line to be placed on the left side of the text. In horizontal writing-modes, it is a synonym of auto.
rightIn vertical writing-modes, this keyword forces the line to be placed on the right side of the text. In horizontal writing-modes, it is a synonym of auto.
| Initial value | auto |
|---|---|
| Applies to | all elements |
| Inherited | yes |
| Computed value | as specified |
| Animation type | discrete |
text-underline-position =
auto |
[ under || [ left | right ] ]
We create two example paragraphs:
<p class="horizontal"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam consectetur ac turpis vel laoreet. Nullam volutpat pharetra lorem, sit amet feugiat tortor volutpat quis. Nam eget sodales quam. Aliquam accumsan tellus ac erat posuere. </p> <p class="vertical"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam consectetur ac turpis vel laoreet. Nullam volutpat pharetra lorem, sit amet feugiat tortor volutpat quis. Nam eget sodales quam. Aliquam accumsan tellus ac erat posuere. </p>
Our CSS looks like this:
p {
font-size: 1.5rem;
text-transform: capitalize;
text-decoration: underline;
text-decoration-thickness: 2px;
}
.horizontal {
text-underline-position: under;
}
.vertical {
writing-mode: vertical-rl;
text-underline-position: left;
}
In this example we set both the paragraphs to have a thick underline. In the horizontal text we use text-underline-position: under; to put the underline below all the descenders.
In the text with a vertical writing-mode set, we can then use values of left or right to make the underline appear on the left or right of the text as required.
The live example looks like this:
Because the text-underline-position property inherits and is not reset by the text-decoration shorthand property, it may be appropriate to set its value at a global level. For example, the under value may be appropriate for a document with lots of chemical and mathematical formulas, which make a large use of subscripts.
:root {
text-underline-position: under;
}
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
text-underline-position |
33 | 12 | 74 | 20 | 12.19 | 33 | 79 | 20 | 12.29 | 2.0 | 4.4.3 | 12.29 |
auto |
33 | 79 | 74 | 20 | 12.1 | 33 | 79 | 20 | 12.2 | 2.0 | 4.4.3 | 12.2 |
from-font |
87 | 87 | 74 | 73 | 12.1 | 87 | 79 | 62 | 12.2 | 14.0 | 87 | 12.2 |
left |
71 | 79 | 74 | 58 | 18.2 | 71 | 79 | 50 | 18.2 | 10.0 | 71 | 18.2 |
right |
71 | 79 | 74 | 58 | 18.2 | 71 | 79 | 50 | 18.2 | 10.0 | 71 | 18.2 |
under |
33 | 79 | 74 | 20 | 12.1 | 33 | 79 | 20 | 12.2 | 2.0 | 4.4.3 | 12.2 |
text-decoration property is a shorthand for setting most text-decoration properties, including text-decoration-line, text-decoration-color, and text-decoration-style. However, it does not set text-underline-position.
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/text-underline-position