When is a fallback font downloaded? - html

If I set a Google font as a fallback font like so:
#font-face {
font-family: 'GoogleFont';
src: url('GoogleFont.ttf');
}
html, body {
font-family: 'myMainFont', 'GoogleFont';
}
Will the Google font only be downloaded to the user's browser if the main font fails?

EDIT
According to the spec, #font-face fonts should only be downloaded when they are required to render the document: http://www.w3.org/TR/css3-fonts/#font-face-loading
The #font-face rule is designed to allow lazy loading of font
resources that are only downloaded when used within a document. A
stylesheet can include #font-face rules for a library of fonts of
which only a select set are used; user agents must only download those
fonts that are referred to within the style rules applicable to a
given page. User agents that download all fonts defined in #font-face
rules without considering whether those fonts are in fact used within
a page are considered non-conformant. In cases where a font might be
downloaded in character fallback cases, user agents may download a
font if it's contained within the computed value of ‘font-family’ for
a given text run.
NOTE:
At the time of writing this answer, different versions of browsers on various systems seem to implement this behaviour wildly differently. All we can do is hope that they will eventually conform to the spec.
Chrome and Firefox (testing others in progress) will only download fonts that are required to render the content that is being displayed, regardless as to what's been specified via #font-face. More importantly, if you specify an #font-face font and then don't use it, e.g.
.css-rule { font-family: Helvetica,'My at-font-face-font',sans-serif; }
Then your custom font face will not be downloaded because it does not need to be.
To examine what fonts are being download and when, open up your network tab during a page load.
EDIT
It appears that the behavior of browsers varies greatly on this issue and I encourage more looking into your individual circumstances.
I can guarantee one thing, however, and that is not all fonts are downloaded all the time in all browsers, just because you've declared them via #font-face.

No: browser implementation varies so you can't trust that fonts will be ignored (even if they are not needed).
The client's OS, browser, and version all cause variant performance -- as do other settings browsers may offer. See Adam's answer about browser compliance for W3's "rule."
Check the resources that get downloaded in your browser here and here in different browsers to see how fonts are treated.
That being said, according to the MDN documentation you can have the "fallback" behavior you're looking for if you specify multiple files in the#font-face src attribute:
#font-face {
font-family: MyFontName;
src: url("MyMainFont.tff"), url("MyBackupFont.ttf");
}
In this example, if the first file isn't found, then we continue down the src list until we find a valid file. Thus, MyBackupFont.tff is only downloaded if MyMainfont.tff can't be found. You can also specify local files in the src by using local("FontName").
By the way, Chris has a great article on how to "use [#font-face] responsibly."

Related

Is it possible to load a font in a webpage when it is mobile phone? (Arial Black for iOS)

The font Arial Black is available on the Mac and PC in general, but not on iOS.
Can a webpage use CSS or perhaps some tricks (such as adding a class "mobile" or "ios" to the <body> element), so that "Arial Black" is added for the webpage, preferably so that the Mac and PC don't have to load it but use the native Arial Black font?
It's probably not safe to assume certain systems have or have not got a particular font loaded locally. And browser/system sniffing is very unreliable.
The CSS font-face rule allows you to give a list of places where a font may be and the browser will go down the list until it finds one it can use. So you can start with looking locally and if it's not there load it.
See https://developer.mozilla.org/en-US/docs/Web/CSS/#font-face
If the local() function is provided, specifying a font name to look
for on the user's computer, and the user agent finds a match, that
local font is used. Otherwise, the font resource specified using the
url() function is downloaded and used.
It gives this example:
#font-face {
font-family: MyHelvetica;
src: local("Helvetica Neue Bold"),
local("HelveticaNeue-Bold"),
url(MgOpenModernaBold.ttf);
font-weight: bold;
}
Obviously you need to substitute whatever names and urls your particular font has on the various systems.

How to load a woff2 font into IE with CSS?

I have IE11 on IE10 mode, and I want to load a css file. I have this
#font-face {
font-family: celestesansbold;
src: url('celestesanscomp-bold-webfont.woff2');
}
And then in the console I see this
CSS3111: #font-face encountered unknown error.
celestesanscomp-bold-webfont.woff2
And in the network tab I see
Name Protocol Method Result Content type Received Time Initiator
.../celestesanscomp-bold-webfont.woff2 HTTP GET 200 font/woff2 (from cache) 0 s
And the don't does not load correctly on the page, the text does not change.
Does anyone know what's wrong?
However regular woff files work, but this is woff2.
Thanks
IE doesn't support woff2. That's why you need to provide woff.
In fact, woff is the standard and it's all you need.
You only load woff2 because it provides better features for less bandwidth in browsers that do support it.
Older versions of IE used to need eot, but it's deprecated now.
However, providing more than one font type file does not mean the browser loads all of them. It stops loading them when it finds one it successfully activates. Which means their order is quite important. You want to put the more modern/efficient ones first and the larger ones (fallbacks) last.
It should be: woff2, woff, eot, svg, ttf/otf.

Prevent Google Chrome from using local fonts

I am using the Raleway font on my website but unless I have the font installed on my local desktop, it does not display properly. Specifically, the weight is always bold. I've had others report this as well. From what I can tell it's because Google is trying to use my desktop fonts for performance but is there any way to prevent this on my site with either CSS or JS? A solution that wouldn't involve changing browser settings. What's strange is that the fonts are displaying properly on Googles Font library. and yes, I see this issue on other websites that us the Raleway font.
The default Google Font APIs include src: local(<font>), which causes the browser to look for the local files before downloading the web font. If you really want to prevent this, you can create your own #font-face declarations and omit the local directives. Use something like the Google Web Font Loader to get the appropriate #font-face declaration, as the Google Font APIs only return the font files for your specific browser and I assume you want to be compatible with all browsers.
Are you importing just the bold style for Raleway? Check that you have 400 (normal) on the import URL for the font. Should look something like this:
https://fonts.googleapis.com/css?family=Raleway:400,700
(that gives you normal and bold)
It is because you do not select desired font-weight. If you inspect that google css file fonts.googleapis.com/css?family=Raleway:300,400,700 you see that last #font-face have font-weight: 700;. In css last #font-face takes precedence over prior definitions. If you do not specify exact font-weight, browser will choose its default - in your example it is bold (700) because it is defined last.

Platform Font Face HTML

I know not every platform contains the same font faces. What would happen if a font face that is not known is used? Is it possible to be downloaded or would it choose a different font face?
The browser will use a default font. You can control your styling by coding backup fonts to use if your first pref isn't supported.
Below is an example of styling backup fonts in CSS.
P { font-family: Cambria, Georgia, Serif }
Hope this helps!
Generally, a browser will default to a font that the computer has installed, usually Arial (windows) or Helvetica (mac). There are several solutions, my favorite resource for web fonts is Google Web Fonts, absolutely free. If you have to have a particular font, Typekit has the largest selection, but be prepared to pay!
With Google Web Fonts, literally just google: Google Web font similar to (The Font you want).
Hope this helps!
If the name of font not installed in the user’s system is mentioned in a font-family declaration (or in a <font> tag), then that name is simply ignored. No automatic download takes place. (Downloadable fonts, aka. web fonts, are a different story, but for them, you really specify font URLs and assign names to them.)
The font used is then determined by other factors. If other fonts are listed in the font-family list, they are tried. Failing that, the font of the parent element is used. Ultimately, if we then come to the top level, the document as a whole, without finding any font name known in the system, then the browser’s default font is used. This font is typically changeable by the user, though few people change it. Typically it is Times New Roman in Windows systems.

How to use Segoe Print font in CSS?

I'm trying to make my webpage use the font Segoe Print, which is not a default browser font. I have the ttf file though, is there any way I can employ this .ttf file so that every visitor (no matter what browser) can see the font ?
I searched and found some solutions, one was saying "Convert the font using this site"
but it gives the error:
Microsoft has requested that their font Segoe Print to be blacklisted
by the generator
So how can I use this font on my website ?
I also found a solution that suggests the following CSS rule :
#font-face
{
font-family: myFirstFont;
src: url('Segoe.ttf'),
url('Segoe.eot'); /* IE9 */
}
But, will it work in non-windows browsers? I mean, does the user have to have the ttf file in their computer, or will it be loaded from my website ?
Thanks !
You cannot, in any legal and morally acceptable way. It would be illegal and morally wrong to give advice on committing the crime that such unauthorized use would constitute.
You should thus either abandon the idea or try and find a free font, or a font that may be legally used for a fee, with characteristics sufficiently similar to the font that you want to use.
You can use Kirsle to convert your TTF font to EOT. Then you need to import three format of your font in the top of your CSS, with this format:
#font-face {
font-family: 'Segoe’;
src:url('fonts/Segoe.eot?#’) format(‘eot’),
url(‘fonts/Segoe.woff’) format(‘woff’);
url(‘fonts/Segoe.ttf’) format(‘truetype’);
}
Remeber to have the ?#, it will deceive the IE to only see the first line and download it, as other browsers can't see the first line and will download the TTF format & New browsers will download the WOFF that have a less size, so will download faster.
Simply use font-family: Segoe to change an item's font in your CSS.
Why not buy it? There are reputable sources where you can purchase a license to use this font as a web font.