Vanta Logo
SPONSOR
Automate SOC 2 & ISO 27001 compliance with Vanta. Get $1,000 off.
Up to date
Published
4 min read

Trevor I. Lasn

Staff Software Engineer, Engineering Manager

LH and RLH: The CSS Units That Make Vertical Spacing Easy

Exploring new CSS line-height units that eliminate guesswork from vertical rhythm

The lh unit represents the computed line-height of an element. If an element has line-height: 1.5, then 1lh equals that computed value. This creates a direct connection between text and spacing measurements.

Form fields often contain different text sizes (labels, inputs, error messages). LH units automatically adjust spacing based on the text size, keeping visual harmony even when text scales up/down. If a form field has larger text, its spacing will proportionally increase.

Cards can contain varying amounts of text with different sizes (titles, descriptions, metadata). LH units ensure the padding and gaps between elements stay proportional to the text size. This prevents awkward spacing when text wraps or when card content changes dynamically.

Article text often changes size across different screen sizes. LH units maintain proper spacing ratios between headings and paragraphs as the text scales. This is crucial for readability - as text gets larger or smaller, the whitespace adjusts proportionally.


The rlh unit differs by always referencing the root element’s line height. It provides consistency across the entire document, regardless of where it’s used. This makes it particularly valuable for global spacing patterns.

Layouts need consistent spacing throughout a website. RLH units ensure that spacing between components stays uniform because they reference the root line height, not local text sizes.

This prevents the common issue where different text sizes in components create inconsistent gaps and padding.

When you adjust the root line height, all spacings adjust proportionally, maintaining visual consistency.

Navigation elements often mix different text sizes - think of a logo next to nav items. Using RLH keeps spacing consistent regardless of individual text styles.

RLH prevents the navigation from becoming uneven when text sizes vary. The spacing remains anchored to the root line height, creating a stable visual structure.

Vertical rhythm is about creating a consistent spacing pattern that guides the eye down the page. RLH units excel here because they maintain alignment with the root line height.

This means all elements can snap to the same underlying grid, creating a harmonious flow. When text sizes change, the grid remains stable because it’s tied to the root, not individual elements.

When to Choose LH vs RLH

LH units work best for component-level spacing where you want elements to scale with their text size - think form fields, cards, and article content.

RLH units shine for site-wide spacing patterns where consistency is key - layouts, navigation, and vertical rhythm.

By combining both units thoughtfully, you can create flexible, maintainable layouts that stay visually harmonious across different screen sizes and text scales.

If you found this article helpful, you might enjoy my free newsletter. I share developer tips and insights to help you grow your skills and career.


More Articles You Might Enjoy

If you enjoyed this article, you might find these related pieces interesting as well. If you like what I have to say, please check out the sponsors who are supporting me. Much appreciated!

Webdev
4 min read

Remove Unnecessary NPM Packages with eslint-plugin-depend

We don't need packages to handle basic JavaScript tasks

Aug 13, 2024
Read article
Webdev
3 min read

CSS :has() - The Parent Selector We've Always Wanted

Transform your CSS with :has(), the game-changing selector that finally lets us style elements based on their children.

Dec 4, 2024
Read article
Webdev
4 min read

Speed Up Your Website With rel='preconnect' and increase PageSpeed Insights Score

Using link rel='preconnect' can improve your website's performance by reducing connection setup times to key external domains.

Sep 13, 2024
Read article
Webdev
7 min read

Tips for Reducing Cyclomatic Complexity

Cyclomatic complexity is like counting how many ways a car can go. More options make it harder to drive because you have to make more decisions, which can lead to confusion.

Sep 10, 2024
Read article
Webdev
2 min read

link rel='modulepreload': Optimize JavaScript Module Loading

The rel='modulepreload' indicates that a module script should be fetched, parsed, and compiled preemptively, and stored for later execution

Dec 4, 2024
Read article
Webdev
3 min read

CSS Supports Nesting Now

CSS nesting is finally supported in all major browsers. Write cleaner, organized stylesheets without Sass or Less

Dec 6, 2024
Read article
Webdev
3 min read

The HTML Native Search Element

The search HTML element is a container that represents the parts of the web page with search functionality

Dec 2, 2024
Read article
Webdev
7 min read

How to Land Your First Tech Job

A developer's guide to tech interviews - from someone who sits on both sides of the table

Oct 24, 2024
Read article
Webdev
4 min read

Understanding Vue's Suspense

How the Suspense component manages async dependencies and improves loading states in Vue apps

Aug 23, 2024
Read article

This article was originally published on https://www.trevorlasn.com/blog/css-lh-and-rlh-units. It was written by a human and polished using grammar tools for clarity.