CSS font Property
The font shorthand property sets several font-related properties in a single CSS declaration, including font size, font family, style, weight, and line height.
It provides a convenient way to define typography without writing separate declarations for each property. However, omitted font-related values are reset to their initial values, so the shorthand should be used carefully when modifying existing styles.
font Syntax
The font shorthand combines optional font properties with two required values: font-size and font-family.
Basic Syntax
selector {
font: 16px Arial, sans-serif;
}
Complete Syntax
selector {
font: italic small-caps bold condensed 16px/1.5 Arial, sans-serif;
}
The optional style, variant, weight, and stretch values appear before the required font size. The optional line height follows the font size, separated by a forward slash. The font family comes last.
Common Examples
.text-one {
font: 16px Arial, sans-serif;
}
.text-two {
font: bold 18px Georgia, serif;
}
.text-three {
font: italic 16px/1.6 Verdana, sans-serif;
}
.text-four {
font: normal 400 1rem/1.5 system-ui, sans-serif;
}
.text-five {
font: 600 20px/1.4 "Open Sans", sans-serif;
}
CSS-Wide Keywords
.text {
font: inherit;
}
.text {
font: initial;
}
.text {
font: unset;
}
.text {
font: revert;
}
.text {
font: revert-layer;
}
CSS-wide keywords must be used alone as the value of the shorthand. They cannot be combined with a font size or family in the same declaration.
Property Values
The font shorthand sets several individual font properties at once.
| Component | Description | Required |
|---|---|---|
font-style |
Specifies normal, italic, or oblique text. | No |
font-variant |
Supports the normal and small-caps values in this shorthand syntax. |
No |
font-weight |
Controls the weight or boldness of text. | No |
font-stretch |
Specifies the width variation of the font face. | No |
font-size |
Sets the size of the text. | Yes |
line-height |
Sets the distance between line baselines. | No |
font-family |
Specifies the font family or fallback list. | Yes |
System Font Values
The shorthand also accepts system font keywords that select fonts associated with operating system interface elements.
| Value | Description |
|---|---|
caption |
Uses the font associated with captioned controls. |
icon |
Uses the font associated with icon labels. |
menu |
Uses the font associated with menus. |
message-box |
Uses the font associated with dialog boxes. |
small-caption |
Uses the font associated with small captions. |
status-bar |
Uses the font associated with status bars. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | Not defined for the shorthand as a single value |
| Inherited | Yes, through its font-related longhand properties |
| Applies to | All elements and text |
| Computed value | Determined by the individual longhand properties |
| Animation type | Determined by the individual longhand properties |
| Percentages | Supported by applicable components, including font size and line height |
The shorthand also resets several additional font-related longhand properties, including font feature and variation settings, even though those properties cannot be specified directly through the shorthand syntax.
How It Works
The font shorthand allows multiple typography settings to be declared together.
Separate Properties
.example {
font-style: italic;
font-variant: small-caps;
font-weight: bold;
font-stretch: condensed;
font-size: 18px;
line-height: 1.5;
font-family: Georgia, serif;
}
Equivalent Shorthand
.example {
font: italic small-caps bold condensed 18px/1.5 Georgia, serif;
}
Both examples set the same values for the listed font components. The shorthand also resets other font-related longhand properties, so the declarations are not necessarily identical when additional font settings are already applied.
Minimum Required Declaration
.example {
font: 18px Georgia, serif;
}
Only the font size and font family are required for the ordinary shorthand syntax. Optional components omitted from the declaration are reset to their initial values.
Adding Line Height
.example {
font: 18px/1.5 Georgia, serif;
}
The forward slash separates the font size from the line height. In this example, the line height is 1.5 times the element's font size.
Required Values
A normal font shorthand declaration requires both font-size and font-family.
Valid Declaration
p {
font: 16px Arial, sans-serif;
}
Missing Font Family
p {
font: 16px;
}
This declaration is invalid because the font family is missing.
Missing Font Size
p {
font: Arial, sans-serif;
}
This declaration is invalid because the font size is missing.
System Font Exception
button {
font: menu;
}
A system font keyword is a complete shorthand value and does not require a separately specified size or family.
Setting Font Style
The font-style component controls whether text appears normal, italic, or oblique.
Normal Style
.normal-text {
font: normal 16px Arial, sans-serif;
}
Italic Style
.italic-text {
font: italic 16px Georgia, serif;
}
Oblique Style
.oblique-text {
font: oblique 16px Arial, sans-serif;
}
Important Consideration
Italic and oblique are different font styles. Italic typically uses a specially designed italic face, while oblique uses a slanted face or a synthesized slant when necessary.
Setting Font Variant
The font-variant component of the shorthand can enable small capital letters.
Normal Variant
.normal-variant {
font: normal 16px Georgia, serif;
}
Small Caps
.small-caps-text {
font: small-caps 18px Georgia, serif;
}
Combining Small Caps and Weight
.small-caps-heading {
font: small-caps bold 20px Georgia, serif;
}
Important Consideration
The font shorthand accepts only the limited normal and small-caps variant syntax. For additional typographic features, use properties such as font-variant, font-variant-ligatures, or font-variant-numeric separately.
Setting Font Weight
The font-weight component controls the thickness of text characters.
Normal Weight
.normal-weight {
font: normal 16px Arial, sans-serif;
}
Bold Weight
.bold-weight {
font: bold 18px Arial, sans-serif;
}
Numeric Weight
.medium-weight {
font: 500 16px Arial, sans-serif;
}
.semibold-weight {
font: 600 18px Arial, sans-serif;
}
.heavy-weight {
font: 800 20px Arial, sans-serif;
}
Relative Weight
.heavier-text {
font: bolder 18px Arial, sans-serif;
}
Numeric font weights range from 1 to 1000. The appearance depends on which font faces or variable font weights are available.
Important Consideration
Not every font family includes every weight. Browsers may select the nearest available weight or synthesize a heavier appearance.
Setting Font Stretch
The font-stretch component selects a condensed, normal, or expanded font face when the font family provides suitable width variations.
Condensed Font
.condensed-text {
font: condensed 16px "Arial Narrow", sans-serif;
}
Expanded Font
.expanded-text {
font: expanded 16px "Example Variable Font", sans-serif;
}
Normal Width
.normal-width {
font: normal 16px Arial, sans-serif;
}
Important Consideration
The traditional shorthand syntax supports stretch keywords. To use percentage-based font widths, set font-stretch separately where supported.
Font stretching selects an appropriate font face or width variation. It does not behave like a CSS transform that geometrically scales text.
Setting Font Size
The font-size component determines the size of the text and is required in a normal font shorthand declaration.
Pixels
.pixel-text {
font: 18px Arial, sans-serif;
}
rem Units
.rem-text {
font: 1.125rem Arial, sans-serif;
}
em Units
.em-text {
font: 1.2em Arial, sans-serif;
}
Percentage
.percentage-text {
font: 120% Arial, sans-serif;
}
Font Size Keywords
.small-text {
font: small Arial, sans-serif;
}
.large-text {
font: large Arial, sans-serif;
}
Responsive Font Size
.responsive-heading {
font: 700 clamp(1.5rem, 3vw, 2.5rem)/1.2 Arial, sans-serif;
}
The clamp() function allows the font size to adjust within specified minimum and maximum limits.
Important Consideration
Relative units such as rem and em are useful for scalable typography. Avoid preventing users from resizing text through their browser settings.
Setting Line Height
The optional line-height component controls the vertical spacing between lines of text.
Unitless Line Height
p {
font: 16px/1.5 Arial, sans-serif;
}
A unitless line height is multiplied by the element's font size. In this example, the used line height is 24 pixels.
Pixel Line Height
p {
font: 16px/24px Arial, sans-serif;
}
Percentage Line Height
p {
font: 16px/150% Arial, sans-serif;
}
Heading Line Height
h2 {
font: bold 2rem/1.2 Georgia, serif;
}
Important Consideration
The forward slash must follow the font size and precede the line height. Unitless line heights are often preferable for inherited text styles because they scale with each descendant's own font size.
Setting Font Family
The font-family component specifies the font or list of fonts used to display text. It is required in the normal shorthand syntax.
Single Font Family
p {
font: 16px Arial;
}
Fallback Fonts
p {
font: 16px Arial, Helvetica, sans-serif;
}
Font Family with Spaces
p {
font: 16px "Trebuchet MS", Arial, sans-serif;
}
Generic Font Families
.serif-text {
font: 16px Georgia, serif;
}
.sans-serif-text {
font: 16px Arial, sans-serif;
}
.monospace-text {
font: 14px Consolas, monospace;
}
.system-text {
font: 16px system-ui, sans-serif;
}
Important Consideration
Include a generic fallback family when possible. If the preferred font is unavailable, the browser can use another suitable font.
The font shorthand does not load external font files. Use @font-face or an appropriate font stylesheet to make custom fonts available.
System Font Keywords
System font keywords allow an element to use typography associated with the user's operating system interface.
Menu Font
.menu-label {
font: menu;
}
Caption Font
.caption {
font: caption;
}
Message Box Font
.message {
font: message-box;
}
Status Bar Font
.status {
font: status-bar;
}
Important Consideration
System font keywords must be used alone in the shorthand declaration. The resulting font settings depend on the operating system and browser.
For general interface typography, system-ui can also be used as a generic font family in an ordinary declaration:
body {
font: 1rem/1.5 system-ui, sans-serif;
}
Unlike the menu keyword, system-ui is a font family value and does not automatically supply the font size or other components.
Shorthand Reset Behavior
One of the most important characteristics of the font shorthand is that omitted font properties are reset to their initial values.
Before Using the Shorthand
.example {
font-style: italic;
font-weight: bold;
font-size: 18px;
font-family: Georgia, serif;
}
Applying a New Shorthand
.example {
font-style: italic;
font-weight: bold;
font: 18px Arial, sans-serif;
}
The final font declaration resets the font style to normal and the font weight to normal, because those values were omitted from the shorthand.
Preserving the Desired Values
.example {
font: italic bold 18px Arial, sans-serif;
}
Other Font Properties Affected
The shorthand also resets additional font properties such as font-kerning, font-feature-settings, font-variation-settings, and font-optical-sizing to their initial values.
Setting Additional Properties Afterward
.example {
font: 16px/1.5 "Example Variable Font", sans-serif;
font-kerning: normal;
font-feature-settings: "liga" 1;
}
When additional font settings are needed, place them after the shorthand or use individual longhand properties.
Important Consideration
The shorthand does not reset every property related to text. Properties such as color, text-align, letter-spacing, and text-decoration are not components of the font shorthand.
Order of Values
The order of values matters when using the font shorthand.
General Order
Optional style, variant, weight, and stretch values come first. The required font size follows, then optional line height, and finally the required font family.
Valid Example
p {
font: italic small-caps bold condensed 16px/1.5 Arial, sans-serif;
}
Alternative Optional Value Order
p {
font: bold italic 16px/1.5 Arial, sans-serif;
}
The optional style, variant, weight, and stretch components can appear in different orders, provided their values are unambiguous and they appear before the font size.
Invalid Order
p {
font: Arial 16px bold;
}
This declaration is invalid because the font family appears before the font size.
Incorrect Line Height Placement
p {
font: 16px Arial/1.5;
}
This declaration is invalid because the line height must immediately follow the font size, separated by a slash.
Correct Line Height Placement
p {
font: 16px/1.5 Arial, sans-serif;
}
font Example
This example demonstrates several typography styles using the font shorthand. Each declaration sets the font size and family, with optional weight, style, or line height values.
HTML Example
<div class="font-demo">
<p class="font-normal">Normal font style</p>
<p class="font-bold">Bold font style</p>
<p class="font-italic">Italic font style</p>
<p class="font-small-caps">Small caps font style</p>
<p class="font-line-height">This paragraph uses a larger line height to improve readability when text wraps onto multiple lines.</p>
</div>
CSS Example
.font-demo {
max-width: 420px;
}
.font-demo p {
margin: 0 0 14px;
}
.font-normal {
font: 16px Arial, sans-serif;
}
.font-bold {
font: bold 18px Arial, sans-serif;
}
.font-italic {
font: italic 18px Georgia, serif;
}
.font-small-caps {
font: small-caps 18px Georgia, serif;
}
.font-line-height {
font: 16px/1.8 Arial, sans-serif;
}
Normal font style
Bold font style
Italic font style
Small caps font style
This paragraph uses a larger line height to improve readability when text wraps onto multiple lines.
The examples show how a single font declaration can define different combinations of font properties.
The final paragraph uses a unitless line height of 1.8, creating more vertical space between lines than the other examples.
Common Mistakes
The font shorthand has several syntax requirements that can lead to invalid declarations or unexpected results.
Omitting the Font Family
p {
font: bold 18px;
}
This declaration is invalid because the font family is missing.
Omitting the Font Size
p {
font: bold Arial, sans-serif;
}
This declaration is invalid because the font size is missing.
Placing the Font Family First
p {
font: Arial 18px;
}
The font family must appear after the font size and optional line height.
Using the Wrong Line Height Separator
p {
font: 16px 1.5 Arial, sans-serif;
}
The line height requires a forward slash between the font size and line height.
Forgetting That the Shorthand Resets Values
Declaring font: 16px Arial, sans-serif; resets omitted font components, including font style and weight, to their initial values.
Using Unsupported Components
Properties such as letter-spacing, text-transform, and color cannot be included in the font shorthand.
Assuming Every Font Weight Exists
A numeric weight such as 600 does not guarantee that the chosen font family provides a distinct weight at that value.
Confusing System Font Keywords with Font Families
The keyword menu represents a system font setting, while system-ui is a generic font family. They are not interchangeable.
Important Considerations
Keep the following points in mind when using the font property:
- Purpose: Sets multiple font-related properties in one declaration.
- Required values: Font size and font family are required in the ordinary shorthand syntax.
- Optional values: Font style, variant, weight, stretch, and line height can be included.
- Value order: Optional components precede the font size, and the font family comes last.
- Line height: Must follow the font size, separated by a forward slash.
- Inheritance: The font-related longhand properties are inherited.
- Reset behavior: Omitted font components are reset to their initial values.
- Additional resets: The shorthand also resets several font feature and variation properties.
- Font size: Supports lengths, percentages, and font size keywords.
- Font family: Supports named fonts and generic fallback families.
- Font weight: Supports keywords and numeric weights.
- Font style: Supports normal, italic, and oblique styles.
- Font variant: Supports normal and small caps in the shorthand syntax.
- Font stretch: Supports traditional font width keywords in the shorthand syntax.
- System fonts: Accepts keywords such as
menuandcaption. - System UI: The
system-uigeneric family can be used in ordinary shorthand declarations. - Fallback fonts: Include a generic family when possible.
- Custom fonts: Must be loaded separately using
@font-faceor another font-loading method. - Accessibility: Use readable font sizes and appropriate line heights.
- Responsive typography: Relative units and functions such as
clamp()can help text adapt to different screens. - CSS cascade: Later shorthand declarations can override earlier longhand declarations.
- Browser support: The core shorthand syntax is supported across modern browsers.
Use the font shorthand when several font settings should be defined together. When changing only one component, an individual property such as font-size or font-weight may be safer because it preserves other existing font settings.
Browser Support
The CSS font shorthand property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.
The basic shorthand syntax has long-standing browser support. Support for individual modern font features, variable font capabilities, and advanced font values can vary.
Supported Example
p {
font: italic bold 16px/1.5 Arial, sans-serif;
}
System Font Example
button {
font: menu;
}
Feature Detection
@supports (font: 16px Arial, sans-serif) {
p {
font: 16px/1.5 Arial, sans-serif;
}
}
The @supports rule checks whether the browser recognizes the specified shorthand declaration. It does not confirm that a particular font file is installed or available.
Compatibility Considerations
Test typography with fallback fonts, different operating systems, and browser text scaling. Advanced font features and variable font behavior may differ depending on browser and font support.
For current compatibility information, visit Can I Use? and search for the relevant font feature.
Specifications
The font shorthand property is defined in the CSS Fonts Module, which describes font selection, font families, font sizes, and related typography properties.
CSS Fonts Module Level 4: font Property
Earlier levels of the CSS Fonts specification define the established shorthand syntax and core font selection behavior.
CSS Fonts Module Level 3: font Property
For additional information about CSS font properties and their behavior, see MDN Web Docs.
