CSS text-underline-offset Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Typography

What You’ll Learn

The text-underline-offset property controls how far an underline sits from text — useful for links, headings, and refined typography.

01

Offset

Move underline.

02

auto

Browser default.

03

Length

px, em, %.

04

Links

Better spacing.

05

Decoration

Needs underline.

06

Readability

Clear gaps.

Introduction

The text-underline-offset property in CSS allows developers to control the position of the underline set by the text-decoration property.

This property is particularly useful when you want to adjust the space between the text and its underline, enhancing readability or achieving specific design effects.

Definition and Usage

Use text-underline-offset when a default underline feels too tight against letters — especially on links, underlined headings, or text with descenders like “g” and “y”.

💡
Beginner Tip

Always pair offset with an underline: text-decoration: underline; plus text-underline-offset: 4px; pushes the line farther below the text.

📝 Syntax

The syntax for the text-underline-offset property is straightforward. It accepts length values, such as pixels (px), points (pt), or percentages (%).

syntax.css
element {
  text-underline-offset: length;
}

Here, length is the distance by which the underline is offset from the default position of the text baseline.

Basic Example

text-underline-offset.css
p {
  text-decoration: underline;
  text-underline-offset: 5px;
}

Syntax Rules

  • Accepts auto or a length value (px, em, rem, %).
  • Positive values push the underline farther from the text.
  • Negative values pull the underline closer to the baseline.
  • Only affects underlines — pair with text-decoration-line: underline or shorthand text-decoration: underline.
  • The property is inherited.

Related Properties

  • text-decoration — shorthand for underline, color, style, and thickness
  • text-decoration-line — sets which decoration lines appear
  • text-underline-position — controls underline placement relative to the text
  • text-decoration-thickness — sets underline stroke width

🎯 Default Value

The default value of text-underline-offset is auto, which means the browser determines the offset automatically based on font metrics and text decoration settings.

⚡ Quick Reference

QuestionAnswer
Default valueauto
Push underline downtext-underline-offset: 4px;
Requires underlinetext-decoration: underline;
Relative to font sizetext-underline-offset: 0.15em;
Reset to browser defaulttext-underline-offset: auto;
InheritedYes

💎 Property Values

The text-underline-offset property accepts a keyword or length value.

ValueExampleDescription
lengthtext-underline-offset: 5px;Specifies the distance in pixels, points, or percentages by which the underline is offset from the text baseline.
autotext-underline-offset: auto;Automatically determines the offset based on font metrics and text decoration settings.
auto px em %

When to Use text-underline-offset

text-underline-offset is helpful whenever underline spacing matters:

  • Navigation links — Add breathing room so underlines do not collide with descenders.
  • Headings — Create elegant underlined titles with extra gap below letters.
  • Custom link styles — Fine-tune offset alongside color and thickness.
  • Accessibility — Improve clarity when underline thickness is increased.

👀 Live Preview

Compare how different offset values change underline spacing on the same sentence:

auto Underlined text with browser default offset
2px Underlined text with browser default offset
6px Underlined text with browser default offset
10px Underlined text with browser default offset

Examples Gallery

In this example, we’ll adjust the underline offset for a paragraph of text.

📜 Basic Offset

Start with a simple underline and push it down with a length value.

Example 1 — Custom underline offset on a paragraph

In this example, we’ll adjust the underline offset for a paragraph of text.

index.html
<style>
  p {
    text-decoration: underline;
    text-underline-offset: 5px;
  }
</style>

<h1>Text with Custom Underline Offset</h1>
<p>This paragraph has a custom underline offset.</p>
Try It Yourself

How It Works

The underline is drawn 5 pixels farther from the text than the browser’s default position, creating clearer separation.

📄 Comparisons

See how auto and custom length values differ side by side.

Example 3 — auto vs 8px offset

Compare the browser default with a fixed pixel offset on the same font size.

compare.css
.default {
  text-decoration: underline;
  text-underline-offset: auto;
}

.spaced {
  text-decoration: underline;
  text-underline-offset: 8px;
}
Try It Yourself

How It Works

auto uses font metrics; 8px forces a consistent gap regardless of the typeface.

Example 4 — Underlined heading with em offset

Use em so offset scales proportionally with heading size.

heading.css
h2 {
  text-decoration-line: underline;
  text-decoration-color: #dc2626;
  text-underline-offset: 0.2em;
  font-size: 1.75rem;
}
Try It Yourself

How It Works

An em-based offset grows with the heading’s font size, keeping visual balance at any breakpoint.

♿ Accessibility

  • Do not remove underline meaning — Links should remain identifiable; offset adjusts spacing, not presence.
  • Pair with sufficient contrast — Use text-decoration-color that meets contrast guidelines.
  • Avoid negative offsets on body text — Underlines overlapping letters hurt readability.
  • Test with thick underlines — Larger text-decoration-thickness values often need more offset.

The underline styling stack

Modern underline styling often combines line, color, thickness, and offset. Use the shorthand or longhand properties together for full control.

underline-stack.css
a {
  text-decoration-line: underline;
  text-decoration-color: currentColor;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

🧠 How text-underline-offset Works

1

Underline is enabled

Apply text-decoration: underline or text-decoration-line: underline.

Decoration
2

Offset value is set

Choose auto or a length like 4px or 0.15em.

Distance
3

Browser shifts the line

The underline moves down (positive) or up (negative) relative to its default position.

Render
=

Refined typography

Underlined text looks cleaner with intentional spacing below the glyphs.

Browser Compatibility

The text-underline-offset property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it’s recommended to test your implementation across different browsers to ensure consistent behavior.

Modern browsers · Widely supported

Fine-tuned underline spacing

Current Chrome, Firefox, Safari, Edge, and Opera support text-underline-offset with length and auto values.

96% Browser support
Google Chrome 87+ · Desktop & Mobile
Full support
Mozilla Firefox 70+ · Desktop & Mobile
Full support
Apple Safari 12.1+ · macOS & iOS
Full support
Microsoft Edge 87+ · All versions
Full support
Opera 73+ · All versions
Full support

Testing tip

Verify offset appearance with different fonts and underline thickness values in target browsers.

text-underline-offset property 96% supported

Bottom line: text-underline-offset is reliable for modern typography; test legacy browsers if you must support them.

Conclusion

The text-underline-offset property provides developers with precise control over the position of underlines in text elements.

Whether you need to adjust spacing for better readability or achieve specific design effects, this property allows you to fine-tune the presentation of underlined text on your website.

💡 Best Practices

✅ Do

  • Always enable an underline before setting offset
  • Use em for offsets that scale with font size
  • Increase offset when using thicker underlines
  • Test links with descenders like “g” and “y”
  • Combine with text-decoration-color for branded links

❌ Don’t

  • Expect offset to work without text-decoration-line: underline
  • Use large negative offsets on paragraph text
  • Remove underlines from links and rely on color alone
  • Assume identical offset rendering across every typeface

Key Takeaways

Knowledge Unlocked

Five things to remember about text-underline-offset

Use these points when adjusting underline spacing in CSS.

5
Core concepts
02

auto

Default value.

Default
📏 03

length

px, em, %.

Values
🔗 04

underline

Required pair.

Rule
📝 05

Inherited

Flows to children.

Cascade

❓ Frequently Asked Questions

text-underline-offset controls how far an underline sits from the text baseline. It works with underlines set by text-decoration or text-decoration-line.
The default is auto, which lets the browser choose the offset based on font metrics and decoration settings.
Yes. The property adjusts an existing underline. Apply text-decoration: underline or use text-decoration-line: underline first.
Yes. Negative length values move the underline closer to or through the text, though use them carefully for readability.
Yes, text-underline-offset is inherited. Setting it on a parent affects underlined text inside unless a child overrides it.

Practice in the Live Editor

Open the HTML editor and try different underline offset values on a link.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful