CSS Portal

CSS text-underline-offset Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The text-underline-offset property controls the vertical placement of an underline produced by text decoration relative to the text glyphs. Rather than changing whether an underline is present, it adjusts how far the line sits from the characters so you can fine-tune the visual relationship between the mark and the letterforms. This is particularly useful when working with fonts that have deep descenders, unusual metrics or when a design calls for underlines that appear detached or closely hugging the text.

Because text-underline-offset only modifies the position of the decoration, it is often used together with other typographic properties to achieve a balanced result. For example, the presence and style of an underline are controlled by text-decoration, and the default underline placement can be influenced by text-underline-position. The perceived spacing between underline and letters also depends on font metrics such as font-size and the layout height set by line-height, while the visual weight of the line is set with text-decoration-thickness. Adjusting these together yields consistent, intentional results across different typefaces and sizes.

In practice, you can use text-underline-offset for subtle typographic polishing—moving the underline away from descenders to prevent overlap, creating distinct link underlines, or aligning underlines across mixed font stacks. It also supports creative treatments: animating the offset produces floating underline effects, and combining offsets with custom thickness or dashed styles creates varied visual rhythms. Keep accessibility and legibility in mind — underlines that are too far removed can become visually disconnected from the text they annotate, and underlines that are too close can clash with glyphs, so adjustments should preserve recognizability and sufficient contrast.

Definition

Initial value
auto
Applies to
all elements. It also applies to ::first-letter and ::first-line.
Inherited
yes
Computed value
as specified
Animatable
by computed value type
JavaScript syntax
object.style.textUnderlineOffset

Interactive Demo

The rusty swing set creaked.

Syntax

text-underline-offset: auto | <length> | <percentage>

Values

  • autoThe browser chooses the appropriate offset for underlines.
  • <length>Specifies the offset of underlines as a <length>, overriding the font file suggestion and the browser default. It is recommended to use em units so the offset scales with the font size.
  • <percentage>Specifies the offset of underlines as a <percentage> of 1 em in the element's font. A percentage inherits as a relative value, and so therefore scales with changes in the font. For a given application of this property, the offset is constant across the whole box that the underline is applied to, even if there are child elements with different font sizes or vertical alignment.

Example

<div class="container">
<h1>text-underline-offset examples</h1>
<p>Default underline: <a href="#">Default link</a></p>
<p>Smaller offset: <a href="#" class="offset-small">Small offset</a></p>
<p>Larger offset: <a href="#" class="offset-large">Large offset</a></p>
<p>Negative offset (closer to text): <a href="#" class="offset-negative">Negative offset</a></p>
<p>Thick underline with offset: <a href="#" class="offset-thick">Thick underline</a></p>
</div>
/* Example styles demonstrating text-underline-offset */
* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  padding: 32px;
  background: #f7f8fa;
  color: #111827;
}

.container {
  max-width: 780px;
  margin: 0 auto;
}

p {
  margin: 12px 0;
  line-height: 1.6;
}

a {
  color: #0066cc;
  text-decoration: underline;
  text-decoration-thickness: auto;
  text-underline-offset: 3px; /* default offset for links */
}

/* Variations */
.offset-small {
  text-underline-offset: 1px;
}

.offset-large {
  text-underline-offset: 8px;
}

.offset-negative {
  text-underline-offset: -2px;
}

.offset-thick {
  text-decoration-thickness: 3px;
  text-underline-offset: 6px;
}

Browser Support

The following information will show you the current browser support for the CSS text-underline-offset property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!