CSS Font Property
The CSS Font Shorthand Property
To shorten the code, it is possible to specify all the individual font properties in one declaration.
The CSS font property is a shorthand property for:
Rules for the CSS Font Shorthand Property
- The
font-sizeandfont-familyvalues are required. If one of the other values is missing, their default value are used. - If defined,
font-style,font-variantandfont-weightmust precedefont-size. - If defined,
line-heightmust immediately followfont-size, preceded by "/", like this: 15px/30px. font-familymust be the last value specified.
Example
Use the font shorthand property to set multiple font properties in one declaration:
p.a {
font: 20px Arial, sans-serif;
}
p.b {
font:
italic bold 16px Arial, sans-serif;
}
p.c {
font: italic
small-caps bold 15px/30px Georgia, serif;
}
Try it Yourself »
All CSS Font Properties
| Property | Description |
|---|---|
| font | Sets all the font properties in one declaration |
| font-family | Specifies the font family for text |
| font-size | Specifies the font size of text |
| font-style | Specifies the font style for text |
| font-variant | Specifies whether or not a text should be displayed in a small-caps font |
| font-weight | Specifies the weight of a font |