CSS text-underline-position Property

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

Description

The text-underline-position CSS property is used to control the vertical positioning of underlines applied to text within an HTML element. This property allows web developers to specify whether the underline should be positioned below the text (the default behavior) or above it. By adjusting this property, designers can fine-tune the visual presentation of text and underlines to achieve various styling effects, improving readability and aesthetics in web content.

Initial value
auto
Applies to
All elements
Inherited
Yes
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.textUnderlinePosition

Interactive Demo

C8H10N4O2 is the chemical formula for caffeine.

Syntax

text-underline-position: auto | [ under || [ left | right ] ] 

Values

  • autoThe browser may use any algorithm to determine the underline's position; however it must be placed at or under the alphabetic baseline.
  • underThe underline is positioned under the element's text content. In this case the underline usually does not cross the descenders. (This is sometimes called "accounting" underline.) This value can be combined with 'left' or 'right' if a particular side is preferred in vertical writing modes.

Example

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

Browser Support

The following table will show you the current browser support for the CSS text-underline-position property.

Desktop
Edge Chrome Firefox Opera Safari
1233742012.1
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
33792012.224.4.3

Last updated by CSSPortal on: 2nd January 2024