font
Example
.title {
line-height: 1.2;
font: 700 2rem;
}.title {
font: 700 2rem/1.2 system-ui, sans-serif;
}Size and family are required, and putting line height after the slash avoids the shorthand resetting it.
Common mistakes
- The
fontshorthand is ignored because the family or size is missing. - A later
fontshorthand resetsline-heightandfont-weightset earlier.
Key points
- The shorthand includes both
font-sizeandfont-family, the two required values. - Values follow the order style, weight, then size with optional
/line-height, then family. - Form controls get
font: inheritso they match the page font.
Interview questions
Why do form inputs not use my page font?
Inputs and buttons don't inherit font by default. Add button, input, select, textarea { font: inherit; }.
Does the font shorthand reset other properties?
Yes. Any sub-property you leave out, such as line-height, is reset to its initial value.