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

Who needs a flying car when you have display: grid

I’m not the only one who’s amazed by how much you can do with just a little CSS these days.

Tagged with

I’m more proud of these 128 kilobytes than anything I’ve built since | by Mike Hall | Jul, 2025 | Medium

I don’t normally link to articles on Medium—I respect you too much—and I do wish this were written on Mike Hall’s own site, but this is just too good not to share.

And don’t dismiss this as a nostalgiac case study from the past:

At no point did the constraints make the product feel compromised. Users on modern devices got a smooth experience and instant feedback, while those on older devices got fast, reliable functionality. Users on feature phones got the same core experience without the bells and whistles.

The constraints forced us to solve problems in ways we wouldn’t have considered otherwise. Without those constraints, we could have just thrown bytes at the problem, but with them every feature had to justify itself. Core functionality had to work everywhere, and without JavaScript crutches proper markup became essential.

This experience changed how I approach design problems. Constraints aren’t a straitjacket, keeping us from doing our best work; they are the foundation that makes innovation possible. When you have to work within severe limitations, you find elegant solutions that scale beyond those limitations.

Tagged with

CSS Intelligence: Speculating On The Future Of A Smarter Language — Smashing Magazine

This is a really thoughtful look at the evolution of CSS and the ever-present need to balance power with learnability.

Tagged with

Hiding elements that require JavaScript without JavaScript :: dade

This is clever: putting CSS inside a noscript element to hide anything that requires JavaScript.

Tagged with

Cascading Layouts | OddBird

A workshop on resilient CSS layouts

Oh, hell yes!

Do not hesitate—sign yourself up to this series of three online workshops by Miriam. This is the quickest to level up your working knowledge of the most powerful parts of CSS.

By the end of this you’re going to feel like Neo in that bit of The Matrix when he says “I know kung-fu!” …except kung-fu isn’t very useful for building resilient and maintainable websites, whereas modern CSS absolutely is.

Tagged with

Previously on this day

12 years ago I wrote August in America, day eleven

Sierra Vista, Arizona.

13 years ago I wrote Navicon

Three lines.

17 years ago I wrote Automatic eagle

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

18 years ago I wrote Commentary

Backing up my position on blog comments with some quotes.

20 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?

20 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