CSS Font Fallbacks

A CSS font fallback is a list of fonts that a browser will use if the primary font is not available.

This is important for ensuring that your web pages are readable and look good even if users don't have the fonts you've specified installed on their devices.


To create a CSS font fallback, you can use the font-family property and simply list the fonts you want to use in order of preference, separated by commas.

For example, the following code would create a fallback for the font "Roboto":

Example
        
            p {
    font-family: "Roboto", sans-serif;
}
        
    

This means that if the browser does not have the "Roboto" font installed, it will use the "sans-serif" font family instead.

You can also specify multiple fallback fonts in a comma-separated list.

For example, the following code would create a fallback for the font "Roboto" that would first try the "Arial" font, and then the "Helvetica" font if that is not available:

        
            p {
    font-family: "Roboto", Arial, Helvetica;
}
        
    

It is a good idea to include a generic font family at the end of your font fallback list. This will ensure that your text will still be displayed even if the user's device does not have any of the fonts that you have specified. The five generic font families are:

For example, the following code would create a fallback that would first try the "Roboto" font, then the "Open Sans" font, then the "Helvetica" font, and then the "sans-serif" font if none of the other fonts are available:

        
            p {
    font-family: "Roboto", "Open Sans", Helvetica, sans-serif;
}
        
    

Here are some tips for creating effective CSS font fallbacks: