Lessons on @font-face from the F2E Summit
Last week, I helped host the F2E Summit at Yahoo!, our internal developer event that brings together front end engineers from all around the world. One of the most heavily covered topics was @font-face, and more specifically, it’s pros and cons. Before I forgot all of the great information, I wanted to write it down. This information comes directly from yahoo.com/tablet: Lessons from the Tablet Front Page[1] by Matt Seeley and Case Study:
Wretch New Front Page – Featuring CSS3 for the future[2] by Adam Wang. I’m doing nothing aside from summarizing their findings.
Compatibility
If you think there are problems with <video> and <audio>;, then you might not have looked closely at @font-face. While there is reasonably decent compatibility across desktop browsers via OpenType, TrueType, and WOFF, this not necessarily the case for mobile. iOS 4.1 and earlier only supports SVG web fonts while Android only supports TrueType; iOS 4.2 and later support Open Type, True Type, and SVG fonts. That means your minimum CSS code to support iOS and Android ends up looking like this:
@font-face {
font-family: "Gotham Medium";
font-weight: normal;
font-style: normal;
src: url(gothmed.ttf) format(truetype),
url(gothmed.svg#id) format(svg);
}
Perhaps not the worst thing in the world, but the compatibility issue isn’t yet resolved. Since Internet Explorer prior to 9 does not support multiple values in the src property, it incorrectly parses the above as:
@font-face {
font-family: "Gotham Medium";
font-weight: normal;
font-style: normal;
src: url(gothmed.ttf)%20format(truetype),%20url(gothmed.svg#id)%20format(svg);
}
Catch that? The entire src property value turns into a single URL. That means Internet Explorer 8 and earlier makes a request to your server with this URL:
/gothmed.ttf)%20format(truetype),%20url(gotmed.svg
Note that the part following # is considered a fragment identifier and so isn’t part of the HTTP request. The problem is that this causes a 404 for every page view, so even though earlier Internet Explorer versions don’t support this file format, they still make a request.
To fix this, Matt used a data URI for the TTF file, which Internet Explorer 8 and earlier drops on the floor and doesn’t make any further requests. He also notes that data URIs don’t work for SVG fonts as the data URI size hits some sort of upper limit for iOS.
Unexpected behavior
Matt also pointed out an unexpected behavior when applying text-overflow: ellipsis to SVG fonts. This works fine for other fonts and behaves as expected. When applied to SVG fonts, text-overflow: ellipsis causes all of the characters to disappear except for the ellipsis. So instead of seeing “My text…”, you end up seeing just “…” when an SVG font is used on the element.
Performance
When talking about performance, I’m also talking about user experience, and more importantly, user-perceived performance. Both Matt and Adam touched on the performance issues surrounding @font-face. Matt pointed out the flash of unstyled text (FOUT3) on iOS is actually a flash of no text. He found that even though the page would render, the text that used the web font would not render until the file was completely downloaded. He further noted that the download only began when an element using the web font was received by the browser. This led to applying styles using the web font on the <html> element to trigger download as quickly as possible. The problem isn’t completely solved and is probably worth more research.
Another aspect of web font performance is the size of an individual font file. We in the United States are pretty spoiled when it comes to web fonts since our alphabet has only 26 letters and a few punctuation marks. Adam pointed out that Asian character sets are much large, and so font files can be as large as 4-5 MB per file. So if you’re thinking about using non-standard fonts for Asian web sites, you may want to think again before imposing this on your users.
Conclusion
It appears we still have a lot to learn about @font-face and its use on high-traffic web sites. There are still a lot of caveats to consider, not the least of which are compatibility and performance. I’d like to thank Matt and Adam for sharing their learnings so we can better understand the implications of a design centered around web fonts.
Update (6-Mar-2011) – Included iOS version information for web font support.
References
- yahoo.com/tablet: Lessons from the Tablet Front Page by Matt Seeley
- Case Study:
Wretch New Front Page – Featuring CSS3 for the future by Adam Wang - Fighting the @font-face FOUT by Paul Irish
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.
Both comments and pings are currently closed.




6 Comments
Nice summary Nicholas, thanks. It’s worth noting that you can also prevent malformed requests in IE prior to 9 by appending a question mark ‘?’ after the first URL (ala Fontspring synxtax). IE still downloads the first font-face SRC yet now the URL is valid. This defeats the 404 but does not address FOUT on Android tablets. Using the data-uri knocks out both the IE request and FOUT, one-two punch.
Matt Seeley on April 5th, 2011 at 2:34 pm
There’s also the issue of, is the text readable when funky fonts don’t download? People may specifically block @font-face fonts (for the size/bandwidth reasons mentioned above), or they may simply not support it. I don’t support it. I’ve already seen sites where they made some text very large and then replaced with a narrow font. Meaning, without the narrow font, the text overflows all over the page or even covers other text. Bleh.
Stomme poes on April 6th, 2011 at 5:22 am
To my knowledge, iOS since version 4 supports OTF and TTF as well – SVG fonts are only needed for older versions of iOS.
Robert Nyman on April 6th, 2011 at 6:55 am
@Robert – you’re correct, OTF and TTF support was added in iOS 4.2.
Nicholas C. Zakas on April 6th, 2011 at 5:27 pm
I wondered is there a solution for loading font while @font-face supported and use methods like Cufon when @font-face is not supported? I mean not loading font when it’s not supported and not loading Cufon scripts when it’s not needed. I think this solution can make using custom fonts generally usable.
Paul Irish developed a nice @font-face detector that could help.
I tried to do something like this and it was good. I tested it in more than 10 desktop and mobile browsers and every time I had the custom font. But it doesn’t work when font is loaded from a external CSS file.
Mohsen on April 11th, 2011 at 6:19 pm
Saying in detail, Android supports ttf/otf after 2.2. Don’t support SVG for any version.
Kouji Anzai on April 13th, 2011 at 7:38 pm
Comments are automatically closed after 14 days.