Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Typography

The font property

Reference for the CSS font shorthand: set style, weight, size, line height and family in one declaration, learn the required order and what it resets.

The font property is a shorthand that sets the font style, variant, weight, width, size, line height and family in one declaration. It is compact, but strict: the font size and the font family are required, and every part you leave out is reset to its initial value.

CSS
body {
  font: italic 600 1.125rem/1.6 Georgia, "Times New Roman", serif;
}

Read that line as: style, weight, size / line height, family list. The slash between size and line height is part of the syntax.

Try it

The font shorthand

The last paragraph shows the main trap: the later font declaration silently resets the earlier weight and style.

Syntax

CSS
font: [ [ <font-style> || <font-variant-css2> || <font-weight> || <font-width> ]?
        <font-size> [ / <line-height> ]? <font-family># ]
    | caption | icon | menu | message-box | small-caption | status-bar;
  • Initial value: each longhand at its initial value
  • Applies to: all elements and text
  • Inherited: yes
  • Animatable: as its longhands (size, weight and so on)
  • Computed value: as the longhands

Values

Part Description
font-style normal, italic or oblique. Optional.
font-variant Only normal or small-caps may appear in the shorthand. Optional.
font-weight normal, bold, lighter, bolder or a number from 1 to 1000. Optional.
font-stretch Keywords such as condensed or expanded (percentages are not allowed in the shorthand). Optional.
font-size Required. A length, percentage or keyword such as large.
/ line-height Optional, directly after the size, with a slash: 16px/1.5.
font-family Required, and last. A comma-separated list of families.
system keyword caption, icon, menu, message-box, small-caption or status-bar: use the operating system's font for that interface element.

Usage notes

  • It resets what you omit. font also resets font-stretch, font-size-adjust, font-kerning, font-feature-settings and the other variant properties. It sets line-height back to normal if you leave it out. Put the shorthand before more specific longhands.
  • Missing size or family invalidates it. font: bold Georgia is ignored entirely. Browsers throw away invalid declarations.
  • Order matters. Style, variant, weight and width can come in any order, but they must all come before the size.
  • / needs a size. font: 1.5 Arial is not a line height; a number on its own is read as an invalid size.
  • System fonts. With a keyword like menu, the size, weight and family come from the operating system. Rarely useful on the web, but handy for native-looking controls.
  • Prefer longhands in large codebases. Longhands are easier to read and to override. The shorthand suits a quick base style on body.

Browser support

Supported in every browser.