---
title: "LH and RLH: The CSS Units That Make Vertical Spacing Easy"
description: "Exploring new CSS line-height units that eliminate guesswork from vertical rhythm"
canonical: "https://www.trevorlasn.com/blog/css-lh-and-rlh-units"
author: "Trevor I. Lasn"
published: "2024-12-03"
last-updated: "2024-12-03"
topics: ["CSS"]
---

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

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

By Trevor I. Lasn · Published 2024-12-03 · https://www.trevorlasn.com/blog/css-lh-and-rlh-units

[Browser support for `lh` on webstatus.dev](https://webstatus.dev/features/lh)

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.

```css title="CSS"
/* Traditional approach with magic numbers */
.spacing-old {
  margin-top: 24px;
  padding-bottom: 48px;
}

/* Using lh for precise, text-based spacing */
.spacing-new {
  margin-top: 1lh;
  padding-bottom: 2lh;
}
```

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.

```css title="CSS"
/* Form layouts - maintaining consistent spacing between fields */
.form-field {
  margin-bottom: 1lh;
}
```

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.

```css title="CSS"
/* Card components - ensuring text blocks have proportional spacing */
.card-content {
  padding: 1lh;
  gap: 0.5lh;
}
```

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.

```css title="CSS"
/* Article layouts - creating rhythm between paragraphs and headings */
.article h2 { 
  margin-top: 2lh; 
}

.article p { 
  margin-bottom: 1lh; 
}
```

<br />

[Browser support for `rlh` on webstatus.dev](https://webstatus.dev/features/rlh)

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.

```css title="CSS"
:root {
  line-height: 1.5;
}

.global-spacing {
  --space-unit: 1rlh;
  margin-block: var(--space-unit);
  gap: var(--space-unit);
}
```

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.

```css title="CSS"
:root {
  line-height: 1.5;
}

/* Consistent spacing across components */
.layout-grid {
  gap: 1rlh;
  padding: 2rlh;
}

/* Section spacing */
.section {
  margin-block: 3rlh;
}
```

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.

```css title="CSS"
.nav {
  /* Consistent header spacing */
  height: 4rlh;
  padding-block: 1rlh;
}

.nav-items {
  gap: 1rlh;
}
```

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. 

```css title="CSS"
:root {
  line-height: 1.5;
}

.global-spacing {
  --space-unit: 1rlh;
  margin-block: var(--space-unit);
  gap: var(--space-unit);
}
```

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.
