🔤 CSS font
: Mastering Web Typography with a Single Property
Typography is a crucial part of web design — it affects readability, mood, branding, and user experience. The CSS font
property is a shorthand property that allows you to control multiple font-related styles in one declaration, making your CSS cleaner and your font styling more efficient.
🧾 What is font
?
The font
property lets you set several font-related properties at once, including:
font-style
font-variant
font-weight
font-size
line-height
font-family
By combining these in one line, you can easily manage typography with fewer lines of code.
🧬 Syntax
selector {
font: [font-style] [font-variant] [font-weight] font-size[/line-height] font-family;
}
Important notes:
font-size
andfont-family
are required.- Other values like
font-style
,font-variant
, andfont-weight
are optional. - If you include
line-height
, use a slash/
betweenfont-size
andline-height
. - The order of properties matters — follow the syntax above.
🎯 Example
p {
font: italic small-caps bold 16px/1.5 "Helvetica Neue", Arial, sans-serif;
}
This sets:
font-style: italic;
font-variant: small-caps;
font-weight: bold;
font-size: 16px;
line-height: 1.5;
font-family: "Helvetica Neue", Arial, sans-serif;
🔄 Equivalent Longhand Properties
The example above is the same as:
p {
font-style: italic;
font-variant: small-caps;
font-weight: bold;
font-size: 16px;
line-height: 1.5;
font-family: "Helvetica Neue", Arial, sans-serif;
}
🧠 How It Works
font
sets multiple font properties in one line, simplifying CSS.- If you use the shorthand without all optional values, omitted ones reset to defaults.
- Setting only
font-size
andfont-family
is valid, like:
body {
font: 14px Arial, sans-serif;
}
🛠️ Tips & Best Practices
- Always include
font-size
andfont-family
when using the shorthand. - Use web-safe fonts or web fonts (like Google Fonts) in the
font-family
stack. - Specify a fallback font at the end of the list for reliability.
- Avoid overly complex shorthand if you only want to change one font property to keep your code clear.
- Use relative units (
em
,rem
) for better scalability and accessibility.
✅ Browser Support
Fully supported across all modern browsers and even legacy versions:
- ✅ Chrome
- ✅ Firefox
- ✅ Safari
- ✅ Edge
- ✅ Internet Explorer 6+
🔚 Conclusion
The CSS font
shorthand property is a powerful, concise way to control the look and feel of your text. It helps create readable, attractive typography that enhances your website’s user experience.