The font
CSS shorthand property sets all the different properties of an element's font. Alternatively, it sets an element's font to a system font.
Try it
As with any shorthand property, any individual value that is not specified is set to its corresponding initial value [possibly overriding values previously set using non-shorthand properties]. Though not directly settable by font
, the longhands font-size-adjust
and font-kerning
are also reset to their initial values.
Constituent properties
This property is a shorthand for the following CSS properties:
font-family
0/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
1/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
2/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
3/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
4/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
5/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
Syntax
The font
property may be specified as either a single keyword, which will select a system font, or as a shorthand for various font-related properties.
If font
is specified as a system keyword, it must be one of:
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
8, /* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
9,
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
0,
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
1,
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
2,
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
3.If font
is specified as a shorthand for several font-related properties, then:
- it must include values for:
5Change the radio buttons below to see the generated shorthand and its effect. font-style none normal italic oblique font-variant none normal small-caps font-weight none normal bold font-size 12px 16px 24px line-height none 1.2 3 font-family courier serif sans-serif Arial monospace cursive fantasy system-ui font : font-style optional font-variant optional font-weight optional font-size mandatory line-height optional font-family mandatory This is some sample text.
6Change the radio buttons below to see the generated shorthand and its effect. font-style none normal italic oblique font-variant none normal small-caps font-weight none normal bold font-size 12px 16px 24px line-height none 1.2 3 font-family courier serif sans-serif Arial monospace cursive fantasy system-ui font : font-style optional font-variant optional font-weight optional font-size mandatory line-height optional font-family mandatory This is some sample text.
- it may optionally include values for:
7Change the radio buttons below to see the generated shorthand and its effect. font-style none normal italic oblique font-variant none normal small-caps font-weight none normal bold font-size 12px 16px 24px line-height none 1.2 3 font-family courier serif sans-serif Arial monospace cursive fantasy system-ui font : font-style optional font-variant optional font-weight optional font-size mandatory line-height optional font-family mandatory This is some sample text.
8Change the radio buttons below to see the generated shorthand and its effect. font-style none normal italic oblique font-variant none normal small-caps font-weight none normal bold font-size 12px 16px 24px line-height none 1.2 3 font-family courier serif sans-serif Arial monospace cursive fantasy system-ui font : font-style optional font-variant optional font-weight optional font-size mandatory line-height optional font-family mandatory This is some sample text.
9Change the radio buttons below to see the generated shorthand and its effect. font-style none normal italic oblique font-variant none normal small-caps font-weight none normal bold font-size 12px 16px 24px line-height none 1.2 3 font-family courier serif sans-serif Arial monospace cursive fantasy system-ui font : font-style optional font-variant optional font-weight optional font-size mandatory line-height optional font-family mandatory This is some sample text.
0body, input { font: 14px arial; overflow: hidden; } .propInputCont { float: left; text-align: center; margin-right: 5px; width: 80px; } .setPropCont { float: left; margin-right: 5px; width: 120px; } .propInputs, .setPropCont { margin-bottom: 1em; } .curCss { border: none; border-bottom: 1px solid black; text-align: center; width: 80px; } .mandatory { border-bottom-color: red; } .cf::before, .cf::after { content: " "; display: table; } .cf::after { clear: both; } .tar { width: 40px; text-align: right; } .fontfamily { display: inline-block; }
1body, input { font: 14px arial; overflow: hidden; } .propInputCont { float: left; text-align: center; margin-right: 5px; width: 80px; } .setPropCont { float: left; margin-right: 5px; width: 120px; } .propInputs, .setPropCont { margin-bottom: 1em; } .curCss { border: none; border-bottom: 1px solid black; text-align: center; width: 80px; } .mandatory { border-bottom-color: red; } .cf::before, .cf::after { content: " "; display: table; } .cf::after { clear: both; } .tar { width: 40px; text-align: right; } .fontfamily { display: inline-block; }
2,/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
3 and/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
4 must precede/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
0/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
3 may only specify the values defined in CSS 2.1, that is/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
7 andbody, input { font: 14px arial; overflow: hidden; } .propInputCont { float: left; text-align: center; margin-right: 5px; width: 80px; } .setPropCont { float: left; margin-right: 5px; width: 120px; } .propInputs, .setPropCont { margin-bottom: 1em; } .curCss { border: none; border-bottom: 1px solid black; text-align: center; width: 80px; } .mandatory { border-bottom-color: red; } .cf::before, .cf::after { content: " "; display: table; } .cf::after { clear: both; } .tar { width: 40px; text-align: right; } .fontfamily { display: inline-block; }
8body, input { font: 14px arial; overflow: hidden; } .propInputCont { float: left; text-align: center; margin-right: 5px; width: 80px; } .setPropCont { float: left; margin-right: 5px; width: 120px; } .propInputs, .setPropCont { margin-bottom: 1em; } .curCss { border: none; border-bottom: 1px solid black; text-align: center; width: 80px; } .mandatory { border-bottom-color: red; } .cf::before, .cf::after { content: " "; display: table; } .cf::after { clear: both; } .tar { width: 40px; text-align: right; } .fontfamily { display: inline-block; }
1 may only be a single keyword value./* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
5 must immediately follow/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
0, preceded by "/", like this: "/* Set the font size to 12px and the line height to 14px. Set the font family to sans-serif */ p { font: 12px/14px sans-serif; } /* Set the font size to 80% of the parent element or default value [if no parent element present]. Set the font family to sans-serif */ p { font: 80% sans-serif; } /* Set the font weight to bold, the font-style to italic, the font size to large, and the font family to serif. */ p { font: bold italic large serif; } /* Use the same font as the status bar of the window */ p { font: status-bar; }
2"const textAreas = document.getElementsByClassName["curCss"]; function getProperties[] { return `${getCheckedValue["font_style"]} ` + `${getCheckedValue["font_variant"]} ` + `${getCheckedValue["font_weight"]} ` + `${getCheckedValue["font_size"]}` + `${getCheckedValue["line_height"]} ` + `${getCheckedValue["font_family"]}`; } function getCheckedValue[radioName] { const radios = document.forms[0].elements[radioName]; for [let i = 0; i 1] { old[1].parentElement.removeChild[old[1]]; } css = document.createElement["style"]; css.textContent = `.fontShortHand{font: ${cssFragment}}`; document.body.appendChild[css]; } setCss[];
font-family
must be the last value specified.
Values
const textAreas = document.getElementsByClassName["curCss"];
function getProperties[] {
return `${getCheckedValue["font_style"]} `
+ `${getCheckedValue["font_variant"]} `
+ `${getCheckedValue["font_weight"]} `
+ `${getCheckedValue["font_size"]}`
+ `${getCheckedValue["line_height"]} `
+ `${getCheckedValue["font_family"]}`;
}
function getCheckedValue[radioName] {
const radios = document.forms[0].elements[radioName];
for [let i = 0; i 1] {
old[1].parentElement.removeChild[old[1]];
}
css = document.createElement["style"];
css.textContent = `.fontShortHand{font: ${cssFragment}}`;
document.body.appendChild[css];
}
setCss[];
4See the
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
2 CSS property.const textAreas = document.getElementsByClassName["curCss"];
function getProperties[] {
return `${getCheckedValue["font_style"]} `
+ `${getCheckedValue["font_variant"]} `
+ `${getCheckedValue["font_weight"]} `
+ `${getCheckedValue["font_size"]}`
+ `${getCheckedValue["line_height"]} `
+ `${getCheckedValue["font_family"]}`;
}
function getCheckedValue[radioName] {
const radios = document.forms[0].elements[radioName];
for [let i = 0; i 1] {
old[1].parentElement.removeChild[old[1]];
}
css = document.createElement["style"];
css.textContent = `.fontShortHand{font: ${cssFragment}}`;
document.body.appendChild[css];
}
setCss[];
6See the
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
3 CSS property.const textAreas = document.getElementsByClassName["curCss"];
function getProperties[] {
return `${getCheckedValue["font_style"]} `
+ `${getCheckedValue["font_variant"]} `
+ `${getCheckedValue["font_weight"]} `
+ `${getCheckedValue["font_size"]}`
+ `${getCheckedValue["line_height"]} `
+ `${getCheckedValue["font_family"]}`;
}
function getCheckedValue[radioName] {
const radios = document.forms[0].elements[radioName];
for [let i = 0; i 1] {
old[1].parentElement.removeChild[old[1]];
}
css = document.createElement["style"];
css.textContent = `.fontShortHand{font: ${cssFragment}}`;
document.body.appendChild[css];
}
setCss[];
8See the
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
4 CSS property.font
0See the
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
1 CSS property.font
2See the
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
0 CSS property.font
4See the
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
5 CSS property.font
6See the font-family
CSS property.
System font values
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
8The system font used for captioned controls [e.g., buttons, drop-downs, etc.].
/* Set the font size to 12px and the line height to 14px.
Set the font family to sans-serif */
p {
font: 12px/14px sans-serif;
}
/* Set the font size to 80% of the parent element
or default value [if no parent element present].
Set the font family to sans-serif */
p {
font: 80% sans-serif;
}
/* Set the font weight to bold,
the font-style to italic,
the font size to large,
and the font family to serif. */
p {
font: bold italic large serif;
}
/* Use the same font as the status bar of the window */
p {
font: status-bar;
}
9The system font used to label icons.
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
0The system font used in menus [e.g., dropdown menus and menu lists].
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
1The system font used in dialog boxes.
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
2The system font used for labeling small controls.
Change the radio buttons below to see the generated shorthand and its effect.
font-style
none
normal
italic
oblique
font-variant
none
normal
small-caps
font-weight
none
normal
bold
font-size
12px
16px
24px
line-height
none
1.2
3
font-family
courier
serif
sans-serif
Arial
monospace
cursive
fantasy
system-ui
font :
font-style
optional
font-variant
optional
font-weight
optional
font-size
mandatory
line-height
optional
font-family
mandatory
This is some sample text.
3The system font used in window status bars.
Prefixed system font keywordsBrowsers often implement several more, prefixed, keywords: Gecko implements font
4, font
5, font
6, font
7, font
8, font
9, font-size-adjust
0, font-size-adjust
1, and font-size-adjust
2.