Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Fallback fonts

Tags:

css

fonts

My website uses a rather obscure font that about half the computers can properly read. The font is "Lucida Console". On the computers that can't read this font, they get displayed ugly Times New Roman, is there a way to set the font of my website to Lucida Console but on computers that can't read it, view Arial instead? Using CSS.

like image 603
dukevin Avatar asked Jan 12 '11 20:01

dukevin


People also ask

What is fallback fonts in CSS?

Commonly Used Fallback Fonts This means that you should add a list of similar "backup fonts" in the font-family property. If the first font does not work, the browser will try the next one, and the next one, and so on. Always end the list with a generic font family name.

What is a font fallback name?

A fallback font is a font which will be used if your other choices aren't usable, for example in css if we want one font we would write: font-family: font-name; but we can also set fallback fonts which would be: font-family: font-1, font-2, font-3; If Font 1 isn't available, font-2 would be used, and so on.


2 Answers

you can specify multiple fonts:

p {     font-family: "Times New Roman", Times, serif; } 

The browser will try the first one, if that one isn't available the second, and so forth. In the end it uses the family serif, so the browser chooses any serif font. You should use the monospace family.

So in your case, something like this is what you want:

p {     font-family: "Lucida Console", "Courier New", monospace; } 
like image 200
Jaxan Avatar answered Sep 23 '22 15:09

Jaxan


Further tips:

  • Google css font stack for suggested lists of fonts aimed at certain styles of fonts. 'font stack' is the colloquial name for these font lists.
  • Think cross-platform. Consider adding fonts commonly found on Mac, Linux, iOS, Android, Windows, and other platforms your readers may be using.
  • Always include a generic-family name at the end of your font stack in case the user has none of your desired fonts:
    • serif
    • sans-serif
    • cursive
    • fantasy
    • monospace
  • Include quotes around fonts named with multiple words, or simply quote all font names.
like image 42
Basil Bourque Avatar answered Sep 19 '22 15:09

Basil Bourque