The CSS font: shorthand property lets you set **multiple font-related properties at once** β including font size, font family, weight, style, line-height, and more. It is powerful, compact, and commonly used in production stylesheets.
Note
β Optional values: style, weight, stretch, line-height
β Order matters
π¦ Syntax
font shorthand syntax
font: [font-style] [font-variant] [font-weight]
[font-stretch] <font-size> [/line-height] <font-family>;
/* Minimal */
font: 16px Arial;
/* Full example */
font: italic small-caps 600 condensed 18px/24px "Roboto", sans-serif;π Properties Controlled by font:
| Property | Controlled? | Example |
|---|---|---|
| font-style | β | italic |
| font-variant | β | small-caps |
| font-weight | β | 700 |
| font-stretch | β | condensed |
| font-size | β (required) | 16px |
| line-height | β | 1.5 |
| font-family | β (required) | "Poppins" |
π¨ 1. Minimal Usage (Required Values Only)
Minimal example
p {
font: 16px "Open Sans", sans-serif;
}Only font-size and font-family are required.
π¨ 2. Adding Font Weight
Weight
h1 {
font: bold 32px/40px "Montserrat", sans-serif;
}Sets weight + size + line-height + family.
π¨ 3. Italic + Weight + Size + Family
Italic
em {
font: italic 600 18px "Lora", serif;
}π¨ 4. Full Shorthand Example
Full
.title {
font: italic small-caps 700 expanded 20px/28px "Merriweather", serif;
}Applies every font-related property in one tidy declaration.
π¨ 5. Using font: with System Fonts
System font
body {
font: 15px/1.6 system-ui;
}System fonts are fast and great for UI-like designs.
π¨ 6. Using font: for UI Components
Button font shorthand
button {
font: 600 14px/1 "Inter", sans-serif;
}π Value Order β VERY Important
The property order must follow this exact pattern:
- 1οΈβ£ font-style
- 2οΈβ£ font-variant
- 3οΈβ£ font-weight
- 4οΈβ£ font-stretch
- 5οΈβ£ font-size
- 6οΈβ£ line-height (after a /)
- 7οΈβ£ font-family
Note
π Resetting Fonts Using Shorthand
Reset
* {
font: inherit;
}This sets font values back to the parent, often used in resets.
π§ͺ Real-World Use Cases
1οΈβ£ Typography Scale
scale
h1 {
font: 700 48px/1.1 "Poppins";
}
h2 {
font: 600 32px/1.2 "Poppins";
}
p {
font: 400 16px/1.6 "Poppins";
}2οΈβ£ Neumorphism UI Button
ui font
.btn {
font: 500 14px/1 "Inter", sans-serif;
}3οΈβ£ Dashboard Interface
dashboard
.menu-item {
font: 14px/1.5 system-ui;
}β οΈ Common Mistakes
- β Forgetting that font-size and font-family are required
- β Incorrect order of values
- β Mixing commas between properties (commas allowed ONLY between font families)
- β Expecting font to set text-transform or color (it does NOT)
Note
π₯ Summary
The font: shorthand is essential for efficient, clean typography styling. It controls most font-related values, reduces code noise, and ensures text styles are predictable and consistent.
- font-size + font-family β required
- Order matters β keep syntax correct
- Great for UI & typography systems