Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fallback fonts on special characters

I was wondering if it's possible to, when using @font-face, have a fallback setup so that if the text on my page contains characters that are not accounted for within the font (Japanese characters for example), only those characters are presented in a basic font and every other character remains as the custom font?

I'm imagining that potentially there'd be a mix of two fonts within one paragraph on occasion.

like image 359
sowasred2012 Avatar asked Jul 09 '12 13:07

sowasred2012


People also ask

What is font fallback?

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.

Why is it important to always use fallback fonts?

Therefore, it is very important to always use 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.

Is Helvetica a fallback font?

So the candidate fallback fonts are Arial / Helvetica, Trebuchet MS, and Verdana.


2 Answers

What you described is the default behaviour of a browser - it should naturally fall back to basic font for missing characters.

However, sometimes custom fonts use blank characters, in that case you can try using the unicode-range

For example:

@font-face {
    font-family: BBCBengali;
    src: url(fonts/BBCBengali.ttf) format("opentype");
    unicode-range: U+00-FF;
}

Taken from this interesting article: Creating Custom Font Stacks with Unicode-Range

Unfortunatelly there are browser support issues.

like image 66
jfrej Avatar answered Oct 31 '22 07:10

jfrej


CSS has default fallback to the system font if the specified font doesn't contain a character. You can also specify which font to fall back to.

Example for a serif font:

body {
    font-family: "MyNiceFontWithoutJapanesChars", "common serif font", serif;
}

As long as the fallback font has those characters your default font misses, you should be all right.

like image 26
Jørgen R Avatar answered Oct 31 '22 09:10

Jørgen R