Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CSS is there any need for backup fonts when applying custom fonts to a webpage?

In CSS why is a backup font recommended if I am uploading a custom font for use with the webpage?

I thought the backup fonts were only needed in case the client doesn't have the 1st/2nd/3rd..etc choice installed.

For example if you have this code:

@font-face {
    font-family: MyCustomFont;
    src: url('../fonts/MyCustomFont.ttf');
}

Why is this necessary?

body {
    font-family: MyCustomFont, Arial, Helvetica, sans-serif;
}
like image 599
shfury Avatar asked Jan 25 '13 02:01

shfury


People also ask

Why do we use fallback fonts in CSS?

CSS font Fallbacks provide a backup for the fonts i.e. if one font doesn't work properly then the browser will try the other one. For good coding practice write a generic font family at the end of the list and choose the font fallback within the same font family.

Which CSS rule is required if you need to use your own fonts in the webpage?

The @font-face rule allows custom fonts to be loaded on a webpage. Once added to a stylesheet, the rule instructs the browser to download the font from where it is hosted, then display it as specified in the CSS.

What is a fallback font and why do we need to use it?

A fallback font is a reserve typeface containing symbols for as many Unicode characters as possible. When a display system encounters a character that is not part of the repertoire of any of the other available fonts, a symbol from a fallback font is used instead.


1 Answers

It's not necessary to specify a font stack, but it helps to degrade gracefully in obscure cases when a browser is unable to use the font somehow, e.g. if the HTTP request for the font file times out, the font file itself becomes corrupted or otherwise unusable, the browser doesn't support any of the given font formats, among others.

You should do your best to ensure the custom font gets downloaded and used properly, of course. But things can and do happen that are out of your control sometimes, so it doesn't hurt to still have something nice to fall back to. That's why they're called backup or fallback fonts :)

like image 106
BoltClock Avatar answered Sep 19 '22 20:09

BoltClock