Skip to the workspace
Pebellslearn by building
Fonts and Text Styling  ›  Lesson

Font Style, Variant and the Shorthand

Font Shorthand 12 minfont-style sets the slant, font-variant and its longhands switch glyph forms, and the font shorthand needs a size and a family and resets every sub-property it omits.

css / Font Style, Variant and the Shorthand

Explore each scene at your own pace.

01 · The rule

The rule

Font Style, Variant and the Shorthand

font-style sets the slant, font-variant and its longhands switch glyph forms, and the font shorthand needs a size and a family and resets every sub-property it omits.

Inspect which font properties a shorthand sets and which it resets.

The café's dish descriptions should be in italics, and the prices should line their digits up neatly in a column. Then you discover you can set most font properties in one line, and that one line can quietly undo your italics.

The rule

Style slants, variant reshapes, and font resets whatever it leaves out.

font-style chooses the slant: normal, italic (a true cursive-leaning design, if the font has one) or oblique (the upright letters tilted).

.price ~ p {
  font-style: italic;
}

font-variant turns on alternative glyph forms. The best known is small-caps, which draws lower-case letters as smaller capitals. The more useful modern relatives are the font-variant-* longhands, for example:

.price {
  font-variant-numeric: tabular-nums;
}

Tabular numbers give every digit the same width, so prices stacked in a column line up.

The font shorthand sets several properties at once:

h1 {
  font: italic 700 2.5rem/1.2 "Lora", Georgia, serif;
}

Its grammar is strict:

  • Size and family are required. Without either, the whole declaration is invalid.
  • Style, variant and weight, if present, come before the size.
  • Line height follows the size after a slash: 2.5rem/1.2.
  • The family list comes last.

And the catch: every sub-property you do not mention is reset to its initial value. font: 1rem serif sets the weight back to normal, the style back to normal and the line height back to normal.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.