Underlines and line height

I was thinking about something I wrote yesterday when I was talking about styling underlines on links:

For a start, you can adjust the distance of the underline from the text using text-underline-offset. If you’re using a generous line-height, use a generous distance here too.

For some reason, I completely forgot that we’ve got a line-height unit in CSS now: lh. So if you want to make the distance of your underline proportional to the line height of the text that the link is part of, it’s easy-peasy:

text-underline-offset: 0.15lh;

The greater the line height, the greater the distance between the link text and its underline.

I think this one is going into my collection of CSS snippets I use on almost every project.

Have you published a response to this? :

Responses

5 Shares

# Shared by Schalk Neethling on Thursday, August 14th, 2025 at 8:34am

# Shared by Jules 🍺 on Thursday, August 14th, 2025 at 10:49am

# Shared by zeldman on Thursday, August 14th, 2025 at 4:36pm

# Shared by Sue on Thursday, August 14th, 2025 at 8:53pm

# Shared by Antoine on Thursday, August 21st, 2025 at 8:01am

16 Likes

# Liked by Schalk Neethling on Thursday, August 14th, 2025 at 8:34am

# Liked by Matthias Ott on Thursday, August 14th, 2025 at 8:34am

# Liked by Vic Nash on Thursday, August 14th, 2025 at 9:10am

# Liked by KB on Thursday, August 14th, 2025 at 9:29am

# Liked by Stefan Matei on Thursday, August 14th, 2025 at 10:44am

# Liked by Daniel Burka on Thursday, August 14th, 2025 at 10:44am

# Liked by codebuzz on Thursday, August 14th, 2025 at 12:25pm

# Liked by Tom Elsner on Thursday, August 14th, 2025 at 1:04pm

# Liked by Andrew Douglass on Thursday, August 14th, 2025 at 2:00pm

# Liked by Seth Messer on Thursday, August 14th, 2025 at 4:36pm

# Liked by zeldman on Thursday, August 14th, 2025 at 4:36pm

# Liked by John P. Green on Thursday, August 14th, 2025 at 6:00pm

# Liked by Alastair Slater on Thursday, August 14th, 2025 at 6:08pm

# Liked by Sue on Thursday, August 14th, 2025 at 8:53pm

# Liked by Kyle Johnson on Friday, August 15th, 2025 at 7:34am

# Liked by onpolitics.news on Monday, August 18th, 2025 at 4:22am

Related posts

Making the website for Research By The Sea

Having fun with view transitions and scroll-driven animations.

Displaying HTML web components

You might want to use `display: contents` …maybe.

Who knows?

Had you heard of these bits of CSS? Me too/neither!

Schooltijd

Going back to school in Amsterdam.

Assumption

Separate your concerns.

Related links

The Great CSS Expansion | Butler’s Log

Web development follows a familiar cycle. First we glue together a solution with whatever we have — JavaScript, image hacks, Flash, anything. Then the platform matures, and CSS or HTML eventually makes that same workaround native. Rounded corners, custom fonts, smooth scrolling, sticky positioning: all of these started as JavaScript-heavy hacks before CSS turned them into a single declaration.

We are in another one of those transition moments. A new wave of long-requested CSS features is finally landing, and many of them are explicitly designed to replace patterns that used to require JavaScript. Not as approximations — as first-class platform primitives that handle the edge cases, run in the right thread, and need zero dependencies.

Tagged with

Progressive Web Components | Ariel Salminen

I’m slapping my forehead—progressive web components is a perfect name for what I’ve been calling HTML web components. Why didn’t I think of that?

A Progressive Web Component is a native Custom Element designed in two layers: a base layer of HTML and CSS that renders immediately, without JavaScript, and an enhancement layer of JavaScript that adds reactivity, event handling, and more advanced templating.

Tagged with

Performance-Optimized Video Embeds with Zero JavaScript – Frontend Masters Blog

This is a clever technique for a CSS/HTML only way of just-in-time loading of iframes using details and summary.

Tagged with

An in-depth guide to customising lists with CSS - Piccalilli

Think you know about styling lists with CSS? Think again!

This is just a taste of the kind of in-depth knowledge that Rich will be beaming directly into our brains at Web Day Out

Tagged with

NoLoJS: Reducing the JS Workload with HTML and CSS - Web Performance Calendar

You might not need (much) JavaScript for these common interface patterns.

While we all love the power and flexibility JS provides, we should also respect it, and our users, by limiting its use to only what it needs to do.

Yes! Client-side JavaScript should do what only client-side JavaScript can do.

Tagged with

Previously on this day

13 years ago I wrote August in America, day eleven

Sierra Vista, Arizona.

14 years ago I wrote Navicon

Three lines.

18 years ago I wrote Automatic eagle

I’m going a long way to test this feature.

19 years ago I wrote Commentary

Backing up my position on blog comments with some quotes.

21 years ago I wrote Web 2.0

Everybody’s talking about the new meme on the block: Web 2.0. But what exactly does it mean?

21 years ago I wrote Ligers, Lamarr and Eliza

When I first started reading this National Geographic article about ligers, a creature named in Napoleon Dynamite (it’s probably his favourite animal), I thought it was a parody. When the article began quoting actress Tippi Hedren about ligers and t