Mo’ Bulletproofer @Font-Face CSS Syntax

September 15, 2009

[3-28-10] Where @Font-Face Is Today

Now that web fonts are supported in Firefox 3.5 and 3.6, Internet Explorer, Safari, Opera 10.5, and Chrome, web authors face new questions: How do these implementations differ? What CSS techniques will accommodate all?

Firefox developer John Daggett recently posted a little roundup about these issues and the workarounds that are being explored.
In response to that post, and in response to, particularly, Paul Irish’s work, I came up with the following @font-face CSS syntax. It’s been tested in all of the above named browsers including IE 8, 7, and 6. So far, so good.

The following is a test page that declares the free Droid font as a complete font-family with Regular, Italic, Bold, and Bold Italic. View source for details.

Alert: Be aware that Readable Web has released it’s first @font-face related software utility for creating natively compressed EOT files quickly and easily. It has it’s own web site and, in addition to the utility itself, the download package contains helpful documentation, a test font, and an EOT test page. It’s called EOTFAST If you’re working with @font-face, it’s a must-have.

Here’s The Mo’ Bulletproofer Code:


@font-face{ /* for IE */
font-family:FishyFont;
src:url(fishy.eot);
}
@font-face { /* for non-IE */
font-family:FishyFont;
src:url(http://:/) format("No-IE-404"),url(fishy.ttf) format("truetype");
}

The above code solves the two biggest one big problem I found in my own testing. See “Solving A Problem With IE 6, 7, and 8″ down below.

  1. [Update:] As of Opera 10.5, Opera has very full-featured @font-face support. Synthesized bolding and italic still don’t work as of 10.51, but the developers are working on it and it should arrive soon.
    Therefore, the following harsh information is now, happily, obsolete and I can now travel to Norway in safety.
    The following won’t work in Opera 10:

    @font-face {
    font-family: FishyFont;
    src: url(fishy.eot); /* for IE */
    src: local(FishyFont), url(fishy.ttf) format("truetype"); /* for non-IE */


    Opera will not accept an @font-face rule containing a src target with an EOT extension. This is apparently by design. I believe the standards-compliant approach is for the browser to ignore a rule it doesn’t un­der­stand and move on to the next. (But in Opera it seems that defeating EOT is a higher priority, lending credence to Joe Clark’s recent assertion that Opera 10 just plain sucks.)

Solving A Problem With IE 6, 7, and 8

In an @font-face rule containing a font file extension that IE doesn’t support – TTF/OTF – or format hints – format("truetype") – that IE can’t understand, IE still attempts to resolve, as a URI, the text contained within the first and last parens following “src:”.
In other words, IE makes a HTTP call in an attempt to access a resource that doesn’t exist. And then waits for the server to respond, which it does, with a 404. This is a performance problem. (And a hidden one, at that – only revealed by using special tools, like Fiddler2, with which you can track and analyze HTTP traffic in and out of the browser.)

I have no problem with the redundancy of having two @font-face rules: one backward compatible for IE 6,7,8 and one forward compatible for the others and IE-Next. I prefer NOT co-mingling the standards compliant declarations with the backwards-compatible declarations and think it will be a far less confusing, and more debuggable approach in the long run – especially in a complicated page with several fonts and weights in play. So all of this is fine by me – as I see it, it’s CSS that more accurately maps to the different implementations, file formats, and rendering engines involved.

Provided this syntax survives hard and extensive testing – which it shoulddoes, it’s pretty simple – the only con that I can see is some extra bytes in the style sheet.
It makes Opera happy, keeps the @font-face rules separate without relying on conditional comments, avoids the additional HTTP request(s) by IE, and leaves local() as an option, not a requirement.

As an addendum, here’s a copy of my full reply on the W3C mailing list, with an analysis of Paul’s syntax and my reasons for looking to do it another way.

Alert: The following is now obsolete, as well. As of mid-december 2009, Chrome’s standard build features @font-face support without any special enabling.

Note: Currently, Chrome has web fonts off by default, you have to launch chrome.exe with the “–enable-remote-fonts” parameter to enable it. Tip: Use the latest version, too. [12-21-09] Update: The new Chrome Beta no longer requires using the –enable-remote-fonts command line switch. See:@Font-Face Works Automatically In New Google Chrome Beta

(And a special thanks to Ali G for the headline. Glad I axed.)

Update [09-16-09] Re: Paul Irish’s Syntax Using local To Hide Stuff From IE

After considerable back-and-forth between Paul Irish, Scott Kimler, and myself, we’ve seen test pages using the local descriptor that work in Opera, and some that don’t. Error messages vary. In one case, the EOT file is reported as an “invalid src property”. In another, an unquoted font name in the local descriptor is reported as a “declaration syntax error”. And in another, my personal favorite, it reports “web font discarded – malformed” for the EOT.
What we have here seems like a buggy implementation. (My tests reveal other inconsistencies between Opera and Webkit/Firefox, as well. Stay tuned.) Opera is marginal and bugs will, presumably, be fixed. Paul Irish’s solution is a one way to go but with care and awareness of potential pitfalls. (See note in next paragraph: 12-2-09.)
As always, test, test, test.

Update [12-02-09] Re: Font Names And Using The Local() Descriptor

The local() descriptor was deliberately left optional in CSS3. Following up on any potential downsides to using the local() descriptor to specify a name for a font already installed on the local operating system, there is a thread on Typophile about possible problems that might arise. Different Fonts Named The Same: Does This Happen Frequently? Note [12-21-09]: After careful consideration, research, and discussion – I strongly recommend that you don’t use local() at all – except in special situations. Such as when the size of the font is so large that the opportunity to speed up rendering outweighs the risk that the font installed in the local Operating System may be different than the one on your server. Choose wisely. There will be more about this here and elsewhere, soon.

Related Articles:

  1. @Font-Face Works Automatically In New Google Chrome Beta
  2. EOTFAST: A New And Essential Product For @Font-Face Web Fonts
  3. Ten Great Free Fonts Cross-Browser: A Case Study In @Font-Face
  4. @Font-Face News: Opera 10.5 Beta2 Comes Through!
  5. Google Starts Hosting @Font-Face Web Fonts

Sharing Options:

{ 14 comments… read them below or add one }

adi December 16, 2009 at 10:32 am

i am using the same technique for “myriad pro” but not coming in any browser. I have already uploaded eot & ttf files on the server and calling them…..please help

Richard Fink December 16, 2009 at 10:47 am

@adi
Have to see a sample of what you’ve got. Is there a page posted where the CSS can be reviewed and the font files checked?
regards, rich

adi December 18, 2009 at 12:16 am

@ Richard Fink
thanks for prompt reply…
in my css file following code are there :-
@font-face{
font-family:Myriad Pro;
font-weight:normal;
src: url(http://images.techtree.com/ttphase3/images/font/MyriadPro-Regular.eot);
src: url(http://images.techtree.com/ttphase3/images/font/MyriadPro-Regular.ttf) format(“truetype”);
}
body {background:#c1c1c1;margin:0;font-family:Arial, Helvetica, sans-serif;}
h1 {font-family:Myriad Pro,Arial, Helvetica, sans-serif;font-weight:normal;font-size:30px;padding:0px 0px 3px 5px;color:#000;margin:0;}
———————————————————————————–
And in my html page :-

Untitled Document

Reviews

————————————————————————————
fonts are there on the server but it is not reflecting anything in html file ….please help

adi December 18, 2009 at 1:08 am

my html page to which i’ve attached the above css :-

Untitled Document

Reviews

adi December 18, 2009 at 1:10 am

since html code is not coming in this comment i am just telling u that i am using h1 in the html page which is attached to the mentioned css

Muhammad Usman Arshad December 21, 2009 at 5:50 am

@adi
the problem is with your “eot” file that I have just tested.
I tested my eot file from http://www.fontsquirrel.com/fontface/generator and its working fine.

Richard Fink December 21, 2009 at 8:04 am

@adi and Muhammed,

Sorry for the delayed response. And thanks to Muhammed for checking the EOT file. Hope that information helps you.
Two things:
This syntax will not work in IE:
1) @font-face{
2) font-family:Myriad Pro;
3) font-weight:normal;
4) src: url(http://images.techtree.com/ttphase3/images/font/MyriadPro-Regular.eot);
5) src: url(http://images.techtree.com/ttphase3/images/font/MyriadPro-Regular.ttf) format(“truetype”);
}
When IE parses line 5, it overwrites the statement in line 4. In line 4, IE associates Myriad Pro with MyriadPro-Regular.eot and then, in line 5 it changes that association and Myriad Pro is then associated with no font at all.
One answer to this is to follow the syntax recommended in my post.
1) Keep the @font-face declaration for IE separate from the declaration for the other browsers.
2) Use the “404 – Page Not Found” Mask
 url(‘//:’)format(‘No-404′) as described in my post to keep IE from “seeing” the TTF file.
Also, I notice you’re using a resource domain – images.techtree.com. Make sure your server is configured to send the font files with the required access control headers.
In PHP it looks something like this:

<FilesMatch "\.(ttf|otf)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

By default, Firefox 3.5 only allows fonts to be loaded for pages served from the same site.
Either one of these two things can be causing the font not to load in either IE or Firefox.
Regards, Rich

adi December 26, 2009 at 12:42 pm

hi
richard,

both ttf & eot files were not on the same server so i’ve changed them to same server so in mozilla ttf file is getting downloded but still problem is there with IE (eot file).
1)I’ve converted ttf file to eot from this link http://martin.saulis.com/31~ttf_to_eot_svg_online_converter . is it the correct link?
2) how i can check that the fonts i’ve are licensed or not?
3)i am using now “404 – Page Not Found” Mask but nothing is happening in IE (checking eot locally)..why?
4) tell me what to do for chrome?
Help……..

Richard Fink December 26, 2009 at 4:39 pm

@adi
Glad the TTF is now showing up in Firefox.
Now – as for IE:
Your EOT file is no good.
In a valid EOT, the Full name and Family name must match.
As Muhammed pointed out, if you upload a TTF, the Font Squirrel generator fixes this automatically, I believe.
Once you have fixed the EOT file, the same “Mo’ Bulletproofer” syntax will work for the latest Chrome Beta.
Licensing and following the terms of the EULA, if there is one, is your responsibility. I have no advice to give.
Unless the font file has been tampered with, the author of the font is usually included in the font’s internal information. You can check for that either in Fontbook or by double clicking the TTF file in Windows.
Fix the EOT and it will work.

Rich

adi December 27, 2009 at 8:24 am

thank you very much Richard for valuable help.

adi December 27, 2009 at 8:40 am

hi
Richard,

Do you think while downloading the home page the request (to the server) of downloading special font on user’s machine (who dnt have myriad pro) will delay the speed of page to getting downloaded.

According to you how much it (font request) will effect on the total downloading time of the page? total weight of my initial page including css , images ,js & html is not more than 150kb.

Richard Fink December 27, 2009 at 9:29 am

It’s always going to take a little longer for a font to download as opposed to choosing a “web safe ” font on the user’s computer.
But the font files should cache, so this will only happen on the first visit.
Most users have gotten used to waiting a little bit longer the first time they visit a site and 150kb doesn’t seem too large by today’s standards.
Two important things you can do to speed things up are:
1) Gzip the font files. You can cut down the font file sizes greatly.
At least 50% is usual.
2) Set the expires headers on the font files to a far future date so they cache for a long time without generating 304 requests from the browser. (This is to speed up page load on subsequent visits.)
More information on gzipping and setting the expires headers can be found on Steve Souders site:
http://www.stevesouders.com/blog/

rich

adi January 29, 2010 at 2:43 am

I am calling all font files from other domain (because my technical team putting only dynamic content on same domain )
so myriad pro is showing in IE & Chrome but not showing in FF so is there any solution for that (in all versions of FF)?

Jase May 4, 2010 at 6:45 pm

Thanks, this is the only thing that worked on my site :-)

Leave a Comment

{ 12 trackbacks }

Previous post:

Next post: