π 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.
Note
β Font-aware, unlike px
β Great for text-heavy or editorial designs
π¦ The 6 Typography Units
| Unit | Based On | Usage |
|---|---|---|
| ch | Width of the β0β character | Measure text areas, columns |
| ex | x-height of the font | Rarely used, precise typography |
| cap | Height of capital letters | Title alignment & spacing |
| ic | Average glyph advance width | CJK typography |
| lh | Line-height of the element | Vertical spacing |
| rlh | Root line-height | Consistent 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
β οΈ 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
π 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 Case | Best Unit |
|---|---|
| Form input widths | ch |
| Precise lowercase spacing | ex |
| Title spacing aligned to font | cap |
| CJK layout consistency | ic |
| Component internal spacing | lh |
| Design system spacing | rlh |
β οΈ 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
β 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.
Learn more βMDN Docs π