files/en-us/web/css/reference/properties/text-underline-position/index.md
The text-underline-position CSS property specifies the position of the underline which is set using the {{cssxref("text-decoration")}} property's underline value.
{{InteractiveExample("CSS Demo: text-underline-position")}}
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;
auto
from-font
auto was set, with the browser choosing an appropriate position.under
left
auto.right
auto.{{CSSInfo}}
{{csssyntax}}
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 {{cssxref("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:
{{EmbedLiveSample('A_basic_example', '100%', 600)}}
Because the text-underline-position property inherits and is not reset by the {{cssxref("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;
}
{{Specifications}}
{{Compat}}
text-underline-position.