CSS

css/unitless-line-height

line-height is a unitless number (for example 1.5), never px, em or a percentage, so it scales with each element's font size.

drobnastatycznefe-css-architecture

Dlaczego

A length or percentage line height is computed once on the element and inherited as a fixed value, so a heading inside it gets the parent's line height and its lines overlap. A px line height also stays put when the person enlarges text or sets their own spacing, which clips text in fixed-height boxes.

Poprawka

Write the ratio: line-height: 1.5 for body text (at least 1.5 for paragraphs), about 1.1–1.3 for headings. To centre one line in a control, use padding or flex alignment, not a line-height equal to the height. With design tokens, keep the token unitless too (--leading-body: 1.5).

Przykłady

/* bad */
.btn { font-size: 16px; height: 40px; line-height: 40px; }
/* good */
.btn { font-size: 1rem; min-height: 2.5rem; padding-block: 0.5em; line-height: 1.5; }

Źródła

Fakty

Identyfikator
css/unitless-line-height
Waga
drobna
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
css scss less html vue svelte astro
Uczy jej skill
fe-css-architecture CSS architecture and tokens
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain css/unitless-line-height