πŸ”€ Typography Units in CSS β€” ch, ex, cap, ic, lh, rlh

🌐 What Are Typography Units?

Typography units in CSS let you size elements based on font metricsβ€” meaning they scale according to the characteristics of the current font. These units are incredibly useful for text-driven layouts, accessible sizing, and advanced typographic control.

>>β€œTypography units allow your design to adapt to the natural proportions of a font β€” making layouts more harmonious and readable.”

Note

βœ” Fully responsive
βœ” Font-aware, unlike px
βœ” Great for text-heavy or editorial designs

πŸ“¦ The 6 Typography Units

UnitBased OnUsage
chWidth of the β€œ0” characterMeasure text areas, columns
exx-height of the fontRarely used, precise typography
capHeight of capital lettersTitle alignment & spacing
icAverage glyph advance widthCJK typography
lhLine-height of the elementVertical spacing
rlhRoot line-heightConsistent vertical rhythm

πŸ”€ 1. ch β€” Width of β€œ0”

1ch equals the width of the character β€œ0” in the current font. It’s perfect for controlling text widths and monospaced-style layouts.

ch Example

input {
  width: 30ch; /* enough for ~30 characters */
}

Great for form fields, code containers, and text-limited boxes.

πŸ”‘ 2. ex β€” x-height

1ex = height of lowercase letter β€œx”. This unit reflects the visual height of lowercase text.

ex Example

.small-space {
  margin-top: 2ex;
}

Note

⚠️ Browser support varies
⚠️ Fonts differ widely β†’ inconsistent in UI

πŸ”  3. cap β€” Capital Letter Height

1cap equals the height of uppercase letters. Perfect for aligning or spacing titles and headers.

cap Example

h1 {
  margin-bottom: 2cap; /* scales with font’s capital height */
}

Creates elegant spacing that reflects the actual typographic height.

🈢 4. ic β€” Ideographic Character Unit

1ic = width of one ideographic character (CJK: Chinese, Japanese, Korean). Optimized for East Asian typography.

ic Example

.cjk-box {
  width: 20ic;
}

Perfect for designing Japanese/Chinese text layouts with predictable line lengths.

πŸ“ 5. lh β€” Line Height Unit

1lh equals the computed line-height of the element. Fantastic for vertical rhythm and spacing that β€œbreathes.”

lh Example

p {
  margin-bottom: 2lh; /* consistent spacing between paragraphs */
}

Note

⚑ lh references the element’s own line-height β€” NOT inherited.

πŸ“ 6. rlh β€” Root Line Height

1rlh equals the line-height set on the root (html). This ensures consistent spacing in entire design systems.

rlh Example

html {
  line-height: 1.5;
}

.section {
  padding-top: 3rlh; /* predictable across all components */
}

Perfect for global layout spacing and typographic scale systems.

πŸ§ͺ Practical Use Cases

1️⃣ Perfect Text Inputs With ch

Text Field

input.email {
  width: 35ch;
}

Ensures field width fits actual character count intuitively.

2️⃣ Titles Aligned by Typographic Height (cap)

Cap-aligned Layout

h1 {
  padding-top: 1cap;
  padding-bottom: 1cap;
}

3️⃣ Perfect CJK Columns With ic

Japanese Layout

.article {
  width: 45ic;
}

4️⃣ Vertical Rhythm with lh & rlh

Vertical Rhythm

p {
  margin-top: 1lh;
  margin-bottom: 1lh;
}

.section {
  margin-bottom: 4rlh;
}

🎯 Which Typography Unit Should You Use?

Use CaseBest Unit
Form input widthsch
Precise lowercase spacingex
Title spacing aligned to fontcap
CJK layout consistencyic
Component internal spacinglh
Design system spacingrlh

⚠️ Common Mistakes

  • ❌ Using ex for UI spacing β€” inconsistent across fonts
  • ❌ Forgetting that lh depends on computed line-height
  • ❌ Using ch for buttons β†’ width varies with font choice
  • ❌ Mixing typography units with px β†’ inconsistent rhythm

Note

βœ” Avoid ex for critical layout
βœ” cap, lc (coming soon), and lh/rlh are excellent for typography systems

πŸ”₯ Summary

Typography units like ch, ex, cap, ic, lh, rlh create layouts that respond naturally to the characteristics of the font. They bring true typographic precision and consistency to modern CSS.

>>β€œTypography units help your layout breathe in harmony with the font.”

Learn more β†’MDN Docs πŸ“˜