Fonts

Learn how to work with fonts in CSS.

CSS font properties

The font property is known as a shorthand property and can combine several subproperties into a single line of code.

For example:

font: normal italic small-caps bold 16px/120% "Helvetica", sans-serif;

The code above is equivalent to the following:

font-stretch: normal;
font-style: italic; 
font-variant: small-caps; 
font-weight: bold; 
font-size: 16px; 
line-height: 120%; 
font-family: "Helvetica", sans-serif;

It’s not necessary to declare each property. However, because it’s a shorthand property, they need to be in the correct order. Let’s review each of these properties in more detail.

The font-family property

The font-family property defines the element’s default font family.

The selected font isn’t a singular font face but is instead an entire group of sub-fonts, such as sans-serif, Helvetica, Arial, and so on. This group of sub-fonts makes up a “family.”

body {
    font-family: Helvetica;
}

The font-family used should match a font that has either been embedded on the page or is already available on the user’s system. We can also choose multiple fonts, as shown below:

body {
    font-family:
...