Code has been added to clipboard!

The CSS Font Property

Reading time 2 min
Published Sep 8, 2017
Updated Jan 23, 2020

How to change font in CSS

By using the CSS font property, you can define a set of value for the text font:

Example
p.arial-font {
    font: 14px arial, sans-serif;
}      
p.georgia-font {
    font: italic bold 16px/32px Georgia, serif;
}

This property is actually a shorthand for seven subproperties:

The syntax for CSS text styling

To use the CSS fontshorthand, you need to define the subproperties in a certain order:

font: strech style variant weight size/line-height family;

The only values you must specify to make CSS set font properties are size and family. Other values are optional: if you skip them, the default values will be used instead.

Value Default value Explanation
stretch normal Defines if the text is condensed or stretched
style normal Defines if the text is italic or oblique
variant normal Defines if the text is in small caps
weight normal Defines the thickness of the characters
size medium Defines the height of the characters
line-height normal Defines the height of empty spaces between the text lines
family Depends on the browser Defines the font for the characters

Note: the line height must be defined after the font size with a forward slash between these two values (e.g., 20px/20px).

Using keywords for CSS fonts

Instead of defining each subproperty individually, you can also use keywords to make CSS set font styles:

Example
<ul>
    <li style="font: caption;">Captioned Control Font.</li>
    <li style="font: icon;">Icon Label Font.</li>
    <li style="font: menu;">Dropdown Menu Font.</li>
    <li style="font: message-box;">Dialogue Box Font.</li>
    <li style="font: small-caption;">Smaller Caption Font.</li>
    <li style="font: status-bar;">Status Bar Font.</li>
</ul>

Find all the available values in the table below:

Value Description
caption CSS fonts used for captioned controls such as controls and buttons
small-caption A smaller version of the caption font
icon CSS fonts used for icon labels
menu CSS fonts used for various menus
message-box CSS fonts used for dialog boxes
status-bar CSS fonts used for window status bars

Browser support

Chrome
1+
Edge
12+
Firefox
1+
IE
5.5+
Opera
7+
Safari
1+

Mobile browser support

Chrome
18+
Firefox
4+
Opera
10.1+
Safari
1+
Tutorial
CSS3 Features
Syntax
Classes
ID Selectors
Attribute Selectors
Stylesheets
Inline
Internal
External
Box Model
Children Selectors
Pseudo Classes
Pseudo Elements
Variables
Counters
Text
Fonts
Web Fonts
Backgrounds
Background Images
Colors
Gradients
Opacity / Transparency
Shadow Effects
Transitions
Tooltip
Transform
Animations
Layout — Display
Layout — Position
Layout — Float
Layout — Clear
Layout — Horizontal & Vertical Align
Multiple Columns
Introduction
Responsive Web Design — Viewport
Responsive Web Design — Grid View
Responsive Web Design — Media Queries
Responsive Web Design — Flexbox Layout
Responsive Web Design — Images
Responsive Web Design — Videos
Borders
Margin
Padding
Width
Height
Outline
Links
Lists
Tables
Dropdown Menu
Navigation Bar
Images
Image Gallery
Border Images
Forms
Rounded Corners
Buttons
Box-Sizing
Selector Reference
Pagination Examples
Code Examples
CSS3 Browser Support Reference
Functions Reference
Speech Module Reference
Units
Web Safe Font Combinations
Cheat Sheet
:hover
@font-face
@keyframes
@media
align-content
align-items
align-self
all
animation
backface-visibility
background
background-clip
background-color
background-image
background-origin
background-position
background-size
border
border-image
border-radius
border-style
box-shadow
box-sizing
color
columns
filter
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
font
font-family
font-size
font-size-adjust
font-stretch
font-style
font-weight
hanging-punctuation
justify-content
line-height
margin
offset
opacity
order
outline
overflow
padding
perspective
position
resize
tab-size
text-align
text-decoration
text-emphasis
text-transform
text-shadow
transform
transition-property
translate
vertical-align
word-break
word-wrap
z-index