Web/CSS/text-underline-position

From Get docs


The text-underline-position CSS property specifies the position of the underline which is set using the text-decoration property's underline value.


The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Syntax

/* 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: unset;

Syntax

Values

auto
The user agent uses its own algorithm to place the line at or under the alphabetic baseline.
from-font
If 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.
under
Forces 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.
left
In 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 under.
right
In 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 under.
auto-pos '
A synonym of auto, which should be used instead.
above '
Forces the line to be above the text. When used with East-Asian text, using the auto keyword will lead to a similar effect.
below '
Forces the line to be below the text. When used with alphabetic text, using the auto keyword will lead to a similar effect.

Formal definition

Initial value auto
Applies to all elements
Inherited yes
Computed value as specified
Animation type discrete

Formal syntax

auto | from-font | [ under || [ left | right ] ]

Examples

A simple example

Let's take a couple of simple 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:

Setting text-underline-position globally

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;
}

Specifications

Specification Status Comment
CSS Text Decoration Module Level 3The definition of 'text-underline-position' in that specification. Candidate Recommendation Initial definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
text-underline-position Chrome

Full support 33

Edge

Full support 12

Firefox

Full support 74

IE

Full support 6

Opera

Full support 20

Safari Full support 12.1


Full support 12.1


Full support 9

Prefixed'

Prefixed' Implemented with the vendor prefix: -webkit-

WebView Android

Full support 4.4.3

Chrome Android

Full support 33

Firefox Android

No support No

Opera Android

Full support 20

Safari iOS

No support No

Samsung Internet Android

Full support 2.0

above and below

Experimental'Non-standard'

Chrome

No support No

Edge

No support 12 — 79

Firefox

Full support 74

IE

Full support 6

Opera

No support No

Safari

No support No

WebView Android

No support No

Chrome Android

No support No

Firefox Android

No support No

Opera Android

No support No

Safari iOS

No support No

Samsung Internet Android

No support No

auto-pos

Experimental'Non-standard'

Chrome

No support No

Edge

No support 12 — 79

Firefox

No support No

IE

Full support 6

Opera

No support No

Safari

No support No

WebView Android

No support No

Chrome Android

No support No

Firefox Android

No support No

Opera Android

No support No

Safari iOS

No support No

Samsung Internet Android

No support No

from-font Chrome

No support No

Edge

No support No

Firefox

Full support 74

IE

No support No

Opera

No support No

Safari

No support No

WebView Android

No support No

Chrome Android

No support No

Firefox Android

No support No

Opera Android

No support No

Safari iOS

No support No

Samsung Internet Android

No support No

left and right Chrome

Full support 71

Edge

Full support 79

Firefox

Full support 74

IE

No support No

Opera

Full support 58

Safari

No support No

WebView Android

Full support 71

Chrome Android

Full support 71

Firefox Android

No support No

Opera Android

Full support 50

Safari iOS

No support No

Samsung Internet Android

Full support 10.0

under Chrome

Full support 33

Edge

Full support 79

Firefox

Full support 74

IE

No support No

Opera

Full support 20

Safari

Full support 12.1

WebView Android

Full support 4.4.3

Chrome Android

Full support 33

Firefox Android

No support No

Opera Android

Full support 20

Safari iOS

No support No

Samsung Internet Android

Full support 2.0

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.'
Non-standard. Expect poor cross-browser support.
Requires a vendor prefix or different name for use.'
Requires a vendor prefix or different name for use.


See also