Bulletproof @font-face syntax
Let me introduce you to the best way to do your @font-face definitions:
@font-face { font-family: 'Graublau Web'; src: url('GraublauWeb.eot'); src: local('?'), url('GraublauWeb.woff') format('woff'), url('GraublauWeb.ttf') format('truetype'); }
I'll circle back to why this is the best possible solution but let's first review the other techniques' weaknesses. Of course, the problem at the center of this is that IE needs an .eot font, and the other browsers must take a .ttf or .otf.
Okay, let's see what we got here…
Conditional comments (via)
<!-- @font-face{ font-family:'Graublau Web'; src: url('GraublauWeb.otf') format('opentype'); } --> <!--[if IE]> <mce:style type="text/css" media="screen"><! @font-face{ font-family:'Graublau Web'; src: url('GraublauWeb.eot'); } -->
Ugh. Seriously? We'd have to drop that in every html file or have unique iefonts.css files. No fun. Also, ugly.
Double declarations (via)
@font-face{ font-family:'Graublau Web'; src: url('GraublauWeb.eot'); /* here you go, IE */ } @font-face{ font-family:'Graublau Web'; src: url('GraublauWeb.otf'); /* everyone else take this */ }
The problem here is that, as Andrea points out, IE will actually download the .otf file. We can't have extra HTTP connections, so this is typically the solution:
@font-face { font-family: 'Graublau Web'; src url('GraublauWeb.otf') format('opentype'); /* IE no comprende format()! */ }
Because after all, IE doesn't understand the format hint, right? It's true. But what really happens is that IE does a request for this filename:
GraublauWeb.otf')%20format('opentype
Oops, looks like someone forgot a ? in their regular expression! But hey, a 404 is a lot better than grabbing a file that's 20-100k. Let's kill that 404:
Mo’ Bulletproofer (via)
@font-face{ font-family:'Graublau Web'; src: url('GraublauWeb.eot'); /* here you go, IE */ } @font-face{ font-family:'Graublau Web'; src: url(//:) format ('no404'), url('GraublauWeb.otf') format('opentype'); /* tricky! */ }
Richard Fink proposed this alternate syntax actually as a response to this post, but I've included it back here. The trick is to use url(//:), to prevent IE from 404'ing on the ttf/otf file. In his article he lists a few reasons why he prefers the semantics of this alternative. I understand the argument, but I don't like repeating myself, so I'm gonna keep trucking:
The local reference
@font-face { font-family: 'Graublau Web'; src: url(GraublauWeb.eot); src: local('Graublau Web Regular'), url(GraublauWeb.otf) format('opentype'); }
Much more concise and clean. Here, non-IE browsers skip any .eot file and move on. IE will try to parse the second src value, but it can't understand the local() location nor the multiple locations, so it resorts to the EOT instead. Worth noting that IE will always dive to the last src:url() value to start, so this won't work.
src: url(GraublauWeb.eot); src: url(GraublauWeb.otf); /* Yeah IE will only try this one. :( */
The other benefit.. if it just so happens that a user actually has your custom font installed, this'll save them the download. The one catch is that Safari on OS X will use only the Postscript name instead of the full font name; so when they differ, include both names:
Bulletproof @font-face
@font-face { font-family: 'Graublau Web'; src: url('GraublauWeb.eot'); src: local('Graublau Web Regular'), local('Graublau Web'), url('GraublauWeb.otf') format('opentype'); }
Bulletproof @font-face: Smiley variation
@font-face { font-family: 'Graublau Web'; src: url('GraublauWeb.eot'); src: local('?'), url('GraublauWeb.otf') format('opentype'); }
Added 2010.02.04: There has been concern over specifying local font names. The primary reason is that you cede control to the user's machine, potentially showing a locally installed font instead of the one you want to serve. While that will load faster, there's a very small chance the file could be wrong.
To account for this gotcha, I've specified a local font name of ?. Yes, it's a smiley face. The OpenType spec indicates any two-byte unicode characters won't work in a font name on Mac at all, so that lessens the likelihood that someone actually released a font with such a name. This technique is recommended if you think a locally installed version of this font is not in your best interest.
Added 2010.05.05: The smiley variation is my new recommendation. ← Click through to read why.
Demo
I've added a test page with a few syntax variants here for crossbrowser testing
Additional notes and gotchas:
- Including a
font-variantproperty inside the definition will cause it to not work in Safari (4.0.3 tested) as well as IE 6-8. (Thanks Sid) - Including a
font-styleproperty the definition is safe and the definition will still succeed with all browsers, however IE ignore what you define it as.But if you want a bold or italic style of a font to display, you'll need to make two definitions. Read the It Takes Two, Baby section on Nice Web Type's how to use css font face article - Opera will fail if you do not use quotes (single or double) in your local() font name. So:
local('Use Quotes'). I've filed this bug with Opera as it's a spec violation. Thank you to Scott Kimler and Richard Fink for helping with the tireless research on Opera's quirks. - Safari permission error? Some people experience a dialog asking for permission to use a local font. This only happens in webkit. [screenshot]
- Thibault Bardat-Bujoli indicated that this behavior is due to Linotype FontExplorer X. For any font added but not 'activated', it will intercept requests to use it. You can disable this behavior within the FontExplorer UI [jpg]. I have heard no reports of this behavior on machines lacking FontExplorer
- More on my @font-face gotchas post
- Chrome? A few rumors are going around that a Chrome beta or dev build has @font-face support. There is no install of Chrome that has @font-face enabled by default [actually, it's in dev builds now!], however you can enable it in Chrome 3 with an executable switch. I'm keeping this page on @font-face and Google CHrome up to date with all the details.
- You can feed FF, Opera and Safari a truetype but specify it as format('opentype') and it's just fine. So for all intents and purposes, if your font is opentype or truetype, the format hint is optional.
- The font name that specified in your @font-face declaration cannot exceed 31 characters in length. IE will fail on anything larger.
- I first found this bulletproof technique in use by Mark Pilgrim at http://diveintohtml5.org. My hat is off to you, good sir.
SVG? WOFF?
Since Google Chrome won't have typical @font-face support until version 4, we can snag it early by serving it SVG fonts. WOFF is a new format that is officially supported in Firefox 3.6 Can we integrate those into this syntax? Definitely.
@font-face { font-family: 'Graublau Web'; src: url('GraublauWeb.eot'); src: local('?'), url("GraublauWeb.woff") format("woff"), url("GraublauWeb.otf") format("opentype"), url("GraublauWeb.svg#grablau") format("svg"); }
The order of those is deliberate and discussed in the comments here. Hat tip to Snook for being the first to drag SVG into the party. Font Squirrel and Nice Web Type have also been very thoughtful in their work.
I'm confused and lazy. Help?
Want to absorb the benefits of this article instantly? Use Font Squirrel's awesome @font-face generator. It does all of this for you, and more. If you're less lazy, read through Nice Web Type's How To for all the deets.
2009.09.11: Una buona panoramica e questa tecnica in italiano: font-face e Webfonts: come usarli
2009.09.16: I've updated the article with the Mo' Bulletproofer syntax as well as some more detailed gotcha's and notes.
2009.09.18: This blog article has been translated to Japanese
2009.09.22: Added details around the Safari permission error, which Thibault Bardat-Bujoli tracked down to the Linotype FontExplorer X app.
2009.11.08: New sections for SVG/WOFF and the Font Squirrel generator. Link to Nice Web Type's How To article for doing italic along with normal.
2009.11.17: Note on font name length from FontSquirrel.
2009.12.02: Update on Chrome support with link to Chrome and @font-face: it's here!
2010.02.04: Added the smiley variation.
2010.05.05: Changed default recommendation to the smiley variation. A while bunch of new things to consider: @font-face gotchas.
Follow me on twitter: @paul_irish
I like the solution and thanks for test cases.
The only problem I can spot is that IE will never use the local font even if it is present, will it?
Being fonts something totally re-usable I'd love to find a perfect way to split the specific file inclusion for IE and not IE browsers, without usage of ugly un-masked conditional comments.
@Andrea Giammarchi,
Here's what I think would work:
So in this case we'd be using the local font, but couldn't prevent the .eot download, so it may be all for naught. :/
Paul (and Andrea) … Thanks! I've tested your assertions, the code and even played a tad with IE grabbing a local copy.
Paul set me to tinkering
This is great. @font-face never made so much sense until now :)
Wow, I haven't even thought that IE could download both font files.
This is great solution and now we really have to let people know about it.
Thanks Paul.
So STK went ahead and validated everything presented here, as well as verifying that in my comment above, IE will download the EOT even if the font is locally installed.
Great thorough research: Better @font-face syntax @ randsco
LOL @ thorough, 'twas more a "stream of consciousness" thing, but thanks!
I've updated the cross-browser font embedding tutorial, crediting you and Andrea for your contributions.
Thanks for sharing Hopefully, we'll get the word out, before everyone is running around posting two @font-face selectors!
Great work, good to see smarter solutions popup now that a large majority of the browsers support @font-face.
Paul,
In my tests, Opera isn't accepting your syntax.
So far, OK with Safari, FF3.5. But Opera is bombing out.
Have you tested with it, as yet? Maybe I'm missing something.
Seems that Opera doesn't support "local". Once again, unless I'm missing something.
Could we simply use filters?
@font-face{
*font-family:'Graublau Web'; /* here you go, IE 6 and 7 */
*src: url('GraublauWeb.eot'); /* here you go, IE 6 and 7 */
font-family:'Graublau Web'; /* everyone else take this */
src: url('GraublauWeb.otf'); /* everyone else take this */
}
Sorta' di(e)rty, but it ought to work.
So far this is the most "Bulletproof" for me.
This way at least FF can enjoy the benefits of "local" without breaking Opera and Safari doesn't break when using "font-variant". But I'm looking forward to seeing better solutions.
The shame is that, even with this is a new keyword, we are already making hacks
@Eduardo, the web is a hack. :) At least this technique validates (for those that care). But as browser implementations will *always* differ, we can always expect this sort of deal with new technologies.
@eduardo
Hacks are price we pay for freedom from reliance on a single vendor.
@paul
Re: Opera. Yes, I WAS missing something. local() works OK in Opera. But Opera will not accept a call to an EOT file. Opera's Dragonfly debugger explains it as an "invalid src property". Further, unlike the other browsers, Opera doesn't just ignore the rule and move on to the next. It throws out the whole @font-face rule that contains the call to the EOT.
This is quite deliberate. I believe the standards compliant thing to do would be to ignore the rule and attempt to parse the next.
Seems like somebody just doesn't like Microsoft. ;)
Regards, Rich
Did anyone figure out a way yet to use eot files with font-style? As far as I know it shouldn't work in IE by just including the property. But maybe there is a hack to get around this.
Btw ya'll, Richard Fink proposes some new syntax with the double declaration technique due to Opera ruining the party for everyone.
http://readableweb.com/mo-bulletproofer-font-face-css-syntax/
I haven't yet dug into Opera's problems but will update this article with what I find.
After your email, I created some testcases at
http://dl.getdropbox.com/u/2042542/font-face.html using your original bulletproof syntax and adding font declarations. It seems as if IE and Safari can't deal with font-variant.
I've updated this post with Richard Fink's syntax as well as a large section of detailed notes after much research.
I should note that, at this point, the syntax still hasn't shown any reproducible irregularities. (aka. it's bug-free!) But there are certainly some catches with font-style/variant/weight that change things. So expect a secondary post on that. :)
Maybe it's just me, but Firefox 3.5.3 won't render the correct font if a) the custom font is not installed on the local computer and b) the format is defined like so:
…url('/media/font.ttf') format('opentype');
Only this will work:
…url('/media/font.ttf');
About your Safari permission error, it deoesn’t seems to be a Safari issue but instead a Linotype Font Explorer one.
There is a preference controlling the font requests.
At least that’s what I’ve experienced and solved (You just need to set up Safari to ignore the font requests :-)
I’ve got a test page at http://www.thyb.net/cosmos/index-fonts.html and I’m still fighting between postscript names from Safari and full font names in Firefox, the font-variant and the slow loading time.
So I hope I’ll be able to use corectly @font-face now with your great article.
Thanks again.
@Nick Sergeant
Can you take a look at this page and indicate which examples are in the webfont?
http://dl.getdropbox.com/u/39519/webfontsdemo/index.html
I would expect all but the 'locally installed with local font name' to work, but your bug report would indicate none but the 'no format property' one should work.
It'd be unexpected but interesting if the latest FF3.5 on Snow Leopard showed unique behavior. Thanks.
@Thibault
I emailed you privately, but thanks for the report. It's great to track down this permissions issue. So if we can blame it on Linotype Font Explorer, I think we're in the clear. :)
I've updated the article with Thibault's new research around the permissions dialog and FontExplorer X.
First a disclaimer: I haven't tried @font-face yet. My immediate reaction after reading this article is that a conditional IE-only stylesheet is actually the "best" way to handle this - it's widely recognised that all other solutions to make IE use different CSS to the other browsers are essentially hacks, which could possibly break in a year or two when new browsers are launched, or existing browsers are updated, wheras making use conditional comments are supported. Personally I prefer to have all my IE workarounds hidden away in a seperate stylesheet rather than polluting the global styles :)
Now to fix the caching issue.
It takes about 2-4 seconds to see the @fontface font replace the standard html font.
Ideas?
@Rick Hurst,
I hear ya. I don't think this technique puts us at much risk (though a little, certainly, I concede). I mainly just don't enjoy the overhead of conditional comments. I also prefer conditionally classing my body rather than separate ie.css files, and you can't combine the two. But going the conditional comments route is safe, as long as we don't see other browsers adopting EOT-Lite.
@D Ross
I'll likely have a follow post about this (so grab the rss feed!), but can subset the font-file to make it much smaller (like 20k instead of ~50k), definitely cache it heavily. It looks like TypeKit is also introducing a feature where you can choose to have your text visibility:hidden until the font is ready. I haven't experiemented with this but I'm thinking of a few ways we could do something similar.
Also, what if you're using a font that's probably not licensed for web use? Not sure if it really protects me but I change the name of the font file so it's not so apparent. Kind of hard then to declare the local version right?
@D Ross
If the license of the font you acquired or purchased does not allow you to use it with @font-face, then you're breaking the law. That's bad.
There are lots of typefaces that allow this use and they're on fontsquirrel.com, and the league of moveable type, and the webfont.info wiki.
There are an increasing amount of foundries that allow some sort of web embedding. Monotype/Linotype, for example, allow EOT @font-face as well as siFR and Cufòn. So it's worth looking into.
I have a lot more about this sort of thing in my Employing Custom Fonts presentation.
@Paul Irish
Hmm. I was just looking into it. I may be able to set the mod_expires or set caching in the htaccess. I'm not really a "server" guy but it looks easy enough. I'll probably give it a try soon.
hi great post but i could use a little more information. does this functionality only work in IE 8 or latest fire fox? what about previous versions? sorry i havent done my research and just came across this! nice one for the info.
Hi Paul,
I have a site that originally used Cufon for font replacement: http://blog.franklyrealty.com/
All was well and good until the WP 2.8 upgrade. Then Cufon worked on main post page, but not others. I've decided to simply use @font-face b/c ultimately, it's faster and cleaner. BUT…I cannot get it to work in IE or Chrome…and I've followed all the .eot info, etc.
What am I doing wrong?
Thanks for your help!
Hi,
Many thanks for your article, when i tired the sample code of yours with the corresponding font files its worked well in local system. when tried to use my fonts ( i used the thesansplain-black etc… ) its not even working in firefox. what will be the problem here ?
Hi Paul,
Thanks for share all this precious information with the rest of us. It has been most helpful.
Unfortunately, I have been incapable of debugging a weird problem on Safari. On my web site http://www.workingbruno.com, if the page isn´t on cache, you will *not* see the declared font-face, but an alternate rule provided by Modernizr a small javascript library that you surely know… I´m quite lost on this one… don´t know if it´s a browser bug, a Modernizr problem or simply my mistake.
Have you any insight on this?
Thanks for your time.
Best,
B.
@Bruno
I believe the .ttf file may be corrupt. Using webkit inspector I'm seeing the .ttf download, and your h2 is indeed changing, but I think it's falling back to arial, as Nevis fails. I would explore using some other files for the time being.
There is one thing I am not clear about. I have a font in four different variations, say
- font-regular.otf
- font-italic.otf
- font-italic.otf
- font-bolditalic.otf
plus their .eot equivalents.
The style sheet would then look about like this
@font-face { font-family: 'The Font'; src: url(font-regular.eot); src: local('font-regular.otf'), local('The Font'), url(font-regular.otf) format('opentype'); } @font-face { font-family: 'The Font'; src: url(font-bold.eot); src: local('font-bold.otf'), local('The Font'), url(font-bold.otf) format('opentype'); font-weight: bold }and so on.
When I do this, only the last rule is taken in account. What would be the right way to do this?
Thank you for your time
Dieter
@Dieter Raber
I haven't yet experimented heavily with font weight/style/variant along with @font-face, but I've seen plenty of reports of inconsistencies.
My recommendation right now is to name your variations different things and use the names instead of font-style and font-weight to change.
Less than great, but it'll certainly work.
Is there any way to use @font-face in a Blogger blog?
just wanna say that chrome 0.3 support svg font
it seems otf are not working on opera 10
only ttf - am i right?
I created a web page, and I want to use the French Script MT font. Can you help me to use the @ font-face (how to write the code)for the French Script MT font?
Here's to confused and lazy!
I think I've found a way round the problem of IE downloading the font, even when it's already present on the system.
I'm working on a site for a client right now and am using a fairly widely available font (Arial Narrow). However, some older systems don't have it - my Win2K test system, for example. I therefore didn't want every Internet Explorer user to have to download the font just on the offchance they didn't have it already.
The solution I ended up using was a mix of Javascript and the CSS rules already described. First, I made a regular CSS file, with the following:
Next up, I made an additional file called webfont.css, and put in it:
Step three: I grabbed the fantastic JavaScript font detector, available here:
http://www.lalit.org/lab/javascript-css-font-detect
Step four, I wrote a little JS to get called when the page is ready:
…and that's it! If the font is already on the user's machine, it'll display because it's been declared in the regular CSS file. If it's not, then the JavaScript will include the web font (for IE or other browsers), and the second font declared in the regular CSS file - our web one - will then get used.
The only problem is that there's a brief flicker of the old font before the new one appears, as it's being loaded at the end of the document. Any suggestions much appreciated!
I do not seem to get it working with the latest build of chrome. Site works fine with IE and Firefox on several test machines. Anybody has the same problem?
thanks for the code guys. please can the various vendors now play nicely on some kind of a standard, or at least support multiple formats. i use sifr quite often and it just feels like a slow hack to me. i'd like to see embedded fonts getting traction.
my main issue aside from the code is the legality around font licensing. let's face it, no open source fonts really compete with the diversity of the established foundries.
found a helpful online facility to generate woff, eot and svg versions if anybody needs a pretty frontend that does it all.
btw, paul, checked out aurgasm. what a rad site - keep up the passionate work.
http://www.fontsquirrel.com/fontface/generator
@Diederik
chrome & iphone = svg
ie = eot
ff = woff
@murraybiscuit
sorry, just saw the font-squirrel link. scratch that.
font-family: helvetica,arial; /* ftw */
@Paul Irish
When using multiple styles and weights, it's worth including
font-style:italic;and/orfont-weight:bold;in the@font-facedeclarations for bold and/or italic fonts, even when assigning each file to its ownfont-family. Without this, using CSS to assign italics or bold will result in Firefox 3.5 to make an italic face oblique (yay, slanty italics) and to make a bold face extra bold.(Of course, if you don't want to bother providing bold and/or italicized text to browsers that don't support
@font-face, then resetting everything to normal weight and style will have the same effect.)The permissions error will also show up in Firefox for Mac if you've got a font on a separate partition, in my case, for Boot Camp.
Very useful….nice & clear thanks
Nice article. Shame there's no decent support for converting fonts for IE on Mac yet. Not that I can find anyway.
Fontforge http://fontforge.sourceforge.net/ is available for Mac as well as for Windows and Linux. The interface is pants and it requires X11 but it has a lot of functionality.
@David Bennett
I wrote a similar script, basically attempting to detect if @font-face was supported.. Using the same basic technique, but a little bit more robust. It's a hard problem to solve..
http://paulirish.com/2009/font-face-feature-detection/
As for defeating the FOUT, you can run my test there in the <head> so that's gonna be your fastest way to get things moving.
@Erik Vorhes
Thanks for the comment on font-style and such. I haven't yet done much research in this area but hope to see something soon. I know Opera has had some troubles integrating font-style into the @font-face declarations.
@Nathan Hammond , Oh nice. thanks for the heads up on that. Just yesterday I found yet another reason you may get that permissions error, too.
@Andy, I'd really suggest using the Font Squirrel generator for all your conversion needs: http://www.fontsquirrel.com/fontface/generator
@Paul Irish
For what it's worth, it appears that Opera 10.10 doesn't have problems with
font-styleorfont-weight.@Paul Irish
That's a good shout. I didn't want it slow the page loading, but then I guess it makes more sense for it to take a second longer to load the page in the first place than to do the nasty flash! Liking the approach to calling the font-face file as well; anything that cuts down on server requests is always to be supported!
Thanks! I was looking to for a tutorial for embedding fonts!
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
Am I just imagining this somehow? All of my tests have confirmed it but none of you bloggers have mentioned it..
If the name specified in font-family:'name'; is not the real name of the font then IE won't use the font when you assign that font in a style rule. At the very least, this makes the character limit a potential problem. It also means that FF will use their local font if it exists, even if you don't specify any local sources, because if the font-family: = "the real name of the font", and that font is installed on the system, then FF will use the local font.
Am I missing something here? Can anyone else either confirm this (so I know I am not just losing my mind) or prove it wrong (and wake me up from this strange dream).
I also can not understand why any of you would want to use local fonts at all. Haven't you ever encountered messed up fonts installed on people's computers? They are not actually all that uncommon. And with @font-face inspiring many inexperienced people to start doing their own font conversions, the number of messed up fonts in the wild is only going to increase.
I checked on some of the browser screen capture services and found a good number of their systems to have faulty fonts installed. Most of the screens looked perfect but in some cases my font was clearly being used but it had a different Q and K. On a different test with a different font a few of the test systems showed bold instead of regular (not a browser rendering difference, clearly the bold version of the font), and I had only defined one font and not defined any styles. The only place the bold version could have come from is their systems.
I have seen such messed up fonts many times while working on other people's computers and always wondered where they came from. Using the Font-Squirrel converter to convert fonts, often produces such fonts where the italic version is named "regular" and the bold version is named "italic" or other such funky naming issues. A good number of their pre-packaged @Font-face kits also have such issues. I have also run into similar naming issues using other font conversion utilities.
This is not so much an issue for me at the moment because right now I am not using @font-face in any professional work (I would like to, but there are still to many wrinkles), and the personal project I am putting together only uses fonts that I personally created and I know for a fact that no local sources will exist.
Don't get me wrong here, I don't mean to cast a bad light on Font-Squirrel or anything. I love what they are doing and in time I am sure all of these issues will be ironed out.
@Lampica Are there any specific examples you can cite? I did not know that there were problems like this. Thanks!
Hi Font Squirrel,
I've been out of town for the past few days. I should be home tomorrow or the next day, at which point I think I can give you a couple specific examples.
I'm very new to web design. Still attending CC for my certificate. I have an html doc that dreamweaver was used to create & has some inline css for the fonts chosen. Font in a red suit for 1st choice in size 36 no headings, 2nd choice is papyrus bold no headings for the title. I have a small amount of text that I only want to be in papyrus bold. I can't seem to figure out where to place the @font-face code etc. or what exactly it should be, even after reading & re-reading every single piece of info on the web. I think I might need someone if at all possible to look at my code. I used the drag & drop features of dreamweaver to create it, because I am just not good enough at writing the html yet. I can't use external style sheets because this is for en ebay template. eBays system is copy & paste for html. So once again my css is inline. I've tried dropping the font files into the font generator from fontsquirrel , but just keep getting an error with a red X in a box. Some of my text was done in photoshop because that text wont ever change so I made it part of the images. But some text will need to change on a regular basis, & also needs to be searchable through tags in eBays system so it can't be an image. How can I find out what the exact code should be & where to place it in the html doc? Thank you for any assistance! Stacey
Update, finally got the font squirrel to generate the zip files, but when I open the demo.html the font doesn't display correctly. When I try to open the .eot file it wont open in IE, neither will the .svg or the .woff, only the tff opens in firefox & displays correctly. Not sure what to do with the css files, except maybe copy the code into my html file, but where to place it exactly, since I'm using inline I'm not sure? Thank you for any assistance, Stacey
@stacey
I would be willing to help you out for free, but I suggest you go post your question at http://www.codingforums.com/forumdisplay.php?f=13 as it will be much more convenient and appropriate for me to help you there. Just create an account there and then post your trouble in the html/css section and I will see it and help.
@Lampica
Thank you for your response. I will go to the link you provided within the next couple of hours. I found out a little while ago, that I need to use embedded CSS. Still not sure how it should look code wise. But will fallow your request shortly. Thank you!
@Font Squirrel
Finally made it Home (a week later than planned). I guess I'll drop you a line through the contact form on the Font Squirrel website and give you some examples among your @font-face kits.
@Lampica
Just wanted to let you know that I did as you said, but was asked to post my question in the private message utility per Apostropartheid, who said she deleted my original post to you. I will repost in the private utility.
Stacey
@Lampica
unable to send you private message @ codingForums.com because they can't find you as a user.
Stacey
@Lampica
Cant post in private utility as system doesn't recognizance user.
@Lampica
cant send you private message cause system doesn't recognize user
@Lampica
just wanted to let you know that I did as you said, but was asked to post my question to you somewhere else, Apostropartheid emailed me back & said there is no user named Lampica & removed my post. Not sure what I should do? I didn't see the reply button until now.
Stacey
Ok, just post it as a general question on the forum. Forget about Lampica. I am not always Lampica. Rest assured, I will see your question, it does not need to be addressed to me specifically. And please relax and give people some time to reply before posting multiple times. It may take me a couple hours - or it may take me a day or two, as I'm very busy. Just be patient though and I will do my best to help if I can.
@Lampica
sorry, there was some sort of system error, none of the posts were showing up, after several hrs. so I didn't think any of went through
U have a REALLY weird thing, maybe someone can help me?
I have a website which is divided into and hosted on two domains: http://www.qqleq.nl and http://www.filmmaken.nl. Hosted with the same provider and as far as I know, on the same apache system. Now I made this simple test.html file (see below). It uses the font files on http://www.filmmaken.nl. The test file works on (the latest) FF, but in (the latest) IE it works only on http://www.qqleq.nl, but NOT on http://www.filmmaken.nl. Also not if I make the font files local. Also not if I add an .htaccess file as suggested on some websites. How can the SAME script work on one domain and not on the other? I emptied the browser cache, no result. You can see the two identical files on http://www.filmmaken.nl/test.html en http://www.qqleq.nl/test.html . Does anyone have an idea?
@Roemer Lievaart
You're likely using an .eot file that is bound to a specific domain. Use the fontsquirrel generator to make a new eot.
Hy Guys, Hy Paul,
I really like the attempts made here.
Just one thing that bites me.
Firefox < 3.1 supports SVG. Isn't there any way to enable the SVG-Text rendering for Firefox < 3.1?
Hey Paul.
The 'smilie' trick quite clever. Never would have thought of that. I don't know whether the case of having several fonts with the name is common or not, but I'm sure it happens every now and then. This seems like a great way to prevent this special case - I wonder how often it happens.
Z.
Paul,
Thanks for the great work. Please take a look at this issue with Chrome, first reported on doctype.com. In some cases, it will be worth adding a few extra lines to enable synthetic bold/italic transformations to Chrome.
Hi Paul:
I'm trying to learn this and came up with the following:
@font-face {
font-family: 'myfontname';
src: url('http://www.mywebsite.com/font/GOODTIME.eot');
src: local('GOOD TIMES')
url('http://www.mywebsite.com/font/GOODTIME.ttf') format('opentype');
}
I have the eot file and ttf located as above. The problem is that it works in IE8, but not Firefox 3.6. I tried to find out where IE is getting the font, but it disappears if I simulate a typo error both in the first URL *or* the local font name. Can you help?
I'm confused by the references to the "font-variant" descriptor. According to the current CSS3 font spec for the "@font-face" rule (http://www.w3.org/TR/css3-fonts/#font-resources), the only valid descriptors in a "@font-face" rule are:
font-family
src
font-stretch
font-style
font-weight
"font-variant" is not listed.
Undoubtedly, "font-variant" would be extremely useful. Are some browsers simply supporting this as an extension to the "@font-face" rule, or is there something I'm missing in the spec?
@Doug
Good tip. It's going in my upcoming @font-face gotchas roundup.
@Dean Hall
AFAIK the font-variant doesn't belong inside of the @font-face declaration, but rather in your regular element styles.
@Velten
I don't see the support for SVG @font-face in Firefox as you claim:
http://en.wikipedia.org/wiki/Web_typography#Browser_support
"font-variant" definitely does belong in element styles; I was assuming all the talk here was about using it in @font-face rules, which would be very useful for small-caps font files. I'm not sure why it's not in the CSS3 spec, considering the browser can choose a small-caps variant from system fonts; we should be able to provide a small-caps variant in @font-face rules.
@Dean Hall
Gotcha. Yah I agree it makes sense to be able to declare it at that point. I suppose text-transform is another one that was left-out.
I think it has to do with the spec authors being very anti- css macros. :)
@Mike G
You are missing a comma after local(). That should fix it for FF as long as there's no problem with the TTF file - but if you created an EOT from it, it should be fine.
@dean hall
Font variant doesn't belong in the @font-face declaration. And stay away from font-stretch. No meaningful support as yet.
rich
Hi Paul,
first & foremost I thank you for sharing this valuable property with us. I do however have one concern about it.
I still see web designers/developers using sIFR/cufon rather than embedding fonts straightaway.
Do you mind sharing demerits of 'font-face' with us?
Paul, I'd like to make a correction. You state: "The one catch is that Safari on OS X will use only the Postscript name instead of the full font name; so when they differ, include both names"
This is not really true. Safari only supports specifying the font-FAMILY name in a font-family declaration (and as a fall-back, the PostScript name for cases where the other CSS font-* properties cannot select the face you want, such as an ornaments face).
Your code as follows specifically says "Graublau Web Regular" which is a face name and not a family name, and should in fact not work in any browser unless you have a "Graublau Web Regular Regular" face installed! The actual family name is "Graublau Web", which is why the second match succeeds.
The font family name in Safari is exclusively determined from the NameID code 1 (family) as listed here:
http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html
NameID code 2 (face) is not used for matching CSS font-family properties.
E.g. for PlatformID=1:
1="Graublau Web" 2="Normal" -> font-family: "Graublau Web"; (the base face for a family)
or 1="Arial" 2="Narrow" -> font-family: "Arial"; font-stretch: condensed; (an alternate face)
or 1="Arial" 2="Rounded Bold" -> font-family: "ArialMTRounded-Bold" (PostScript name to select an otherwise unselectable face)
Note that IDs 1 & 2 are the 'ordinary' family/face names, and on the Mac (PlatformID=1), a family can have unlimited numbers of faces. On Windows, historically a family can only have Bold and/or Italic faces, so some of what is really the face name has been pushed into the family name, e.g.
PlatformID=3
1="Arial Rounded"
2="Bold"
To compensate for this, name tables can now contain PlatformID=3, NameID=16 & 17 names which should contain the same values as the PlatformID=1, NameID=1 & 2 values (but obviously with different encodings).
Also, to follow up on a comment just above: font-variant does belong in @font-face delcarations, and its omission is an error. There needs to be a way of saying "this is the small-caps face for family WhateverFont".
this simply isn't working for me. here is what i have in the stylesheet.
and in the html i have an unordered list with list items that have the fatboy class. any help would be appreciated. I am testing in IE8 and FF3.5 on my local machine.
Has anyone got @font-face working on iPhone Safari? People claim to have made this work, but when viewed on device no custom fonts are used… Can anyone point me to a working example??? Love to find one as I am beginning to believe this is not actually possible!
iPhone Safari works with SVG fonts and @font-face. You can make these with the font squirrel generator. Snook also wrote up some words about this. :)
My approach has been to load the "ttf" directly for Firefox, as IE will skip over "ttf" and use "eot" and the rest using local lookup for mobiles using "svg" and modern browsers using "woff".
note there is a Safari bug with @font-face and having the following line in your css:
(fonts generated with font squirrel)
only 1 font is loaded (if using several fonts) and is inconsistently displayed
@dubbs
I'm struggling to get an SVG forn working on the iphone using font-face. I have seen an example that works but try as I might mine doesn't. I can only assume it's to do with the font?
@Tallchap
Hmm.. I haven't had a tough time but I'd definitely recommend the FontSquirrel generator for hooking this all up.
Hi i have tryed out your cool font-face but i cant get to work in IE it workes fine i Firefox but not in IE i hade some trouble that the mime type wasent declared in IIS but i solved that..
Please help …
here is my CSS
/* IE */ @font-face{font-family:BellyBold; src:url(/_css/fonts/BellyBold.eot);} @font-face{font-family:BellyBlack; src:url(/_css/fonts/BellyBlack.eot);} /* non-IE */ @font-face { font-family:BellyBold; src:url(//:) format("No-IE-404"), url(/_css/fonts/BellyBold.otf) format("opentype"); } @font-face { font-family:BellyBlack; src:url(//:) format("No-IE-404"), url(/_css/fonts/BellyBlack.otf) format("opentype"); } h1 { font-family: 'BellyBlack', Tahoma; font-size: 30px; line-height: 21px; color:#333333; }Hello ill get to work when i check the html file localy on my coputer but when i set it up on the server it wont work..
Any ideas??
So an issue I ran into, is that I had (apparently) two different copies of a font on two machines and when I loaded up firefox one machine would load the Local font and the other would load the remote font. The one that rendered the Local font was rendering the font different. So my question is, instead of having firefox immediately render the Local font if it is install, can you have it render the remove one, and if that fails to default to the local font?
Bryant, use the smiley variation but put a local declaration behind the rest of the locations.
I managed to get the @font-face working on iPhone Safari taking Paul's advice and it looks great.
Hi Paul,
this article is amazing, thank you so much.. can't wait to play with this soon. And by the way, can I use this excellent script in in the background that is adictive for drawing.. on my site ?
.k
it is not a perfect css code, try on the epiphany browser (gnome). He dont eat it.
after lots of trial those combination works for me in ie, ff . In chrome combination characters ( I am trying indian unicode font having support of combination characters) are broken.
while it is quite fine in IE and FF. I want to make the code such a way that if the browser dont find that perticular font in visitor machine it will load those font face file and if the font is available in visitor's machine . it will laod the font from the visitor's machine.
1. plz guide me which will be the best code for it ?
2.how to rectify the problem with chrome ?
3. I have make files from frontsquirrel, my all files are too big this is also one of my concern.
thanking you
@rapunzel
I would recommend removing the SVG reference. SVG can't do combination characters. It's a real poor font format.
Can't help with size. Your best bet is to aggressively subset the font..
G'luck.
I managed to minimized those file size by subset the font character codes. I want to make browser to check for the font available in the visitor machine, if font available in visitor's machine .. then it will not load the eot/svg/woff file and will use the visitor's machine font in stead of it ( I will put a link for the fonts in the site) so which will be the best suitable option for me ? plz also mension abt the svg file do I have to put is for rendering it in chrome ?
thanking you ..
Why Google Chrome can't render my font?
@FontNotVisible
you have an extra space behind "fatboyslim" in the class .fatboy properties.
Having attempetd to run the code output by FontSquirrel I noticed that if you're on a Windows server then IIS doesn't have the mime types for SVG and OTF set by default, resulting in those files not being found - even when they're there. If you add the mime types via the MMC and either restart IIS or wait for the App Pools to recycle that seems to resolve it.
Hi,
I used FontSquirrel, and it doesn't seem to work on Safari on a Windows platform. I'm using Windows XP SP2, so haven't tested nor on Vista nor on Windows7 though.
Not much of a issue for myself, but thought i mentioned it.
@Wieland
After testing on Vista and W7, it works on Safari on these platforms. So really not a issue. Thanks for the article btw!
Hello!
Please, I need your help! It's urgent!
In my blog, I changed the blog title font "Verdana" to "Titillium". I'm spekaing of the code "font-face". Many fonts as those, in the Fonts folder in my own computer. Did you understand? I also changed the text font and text title to the fonts that don't exist: Titillium, Calibri, Segoe Print, Segoe Script, Lucida Sans Unicode, etc.. On my computer, the fonts exist. But when I went to cyber café or "LAN house", to see my blog, the fonts of the blog title, text and title text, etc. did not work, because the other computers those fonts din't exist or appear exactly, or those fonts were not installed in the Fonts folder of the other computers. At the blog, accept, recognise and there are only six fonts, including Comic Sans MS, which already existed and was installed on all computers. So how do I install the fonts in my own blog for that the fonts work on all computers that do not have those fonts? Then @font-face doesn't work!
I know you counsel me not to use those fonts, but only the standardised fonts by the Blogger. But see the text at the site of FontsQuirrel, the fonts there work perfectly althought I don't have these fonts, but I know what the font are these!
How do I put the CSS @font-face? Where do I find it in my blog's HTML?
Kevin
Chrome in Windows appears to stop rendering my font whenever it sees an 'e' character for some reason. Works fine in Chrome for OS X and every other browser on both OSes. Any ideas? The font is 'Birth Of A Hero'.
TWO SMILEY VARIATION. Avoid problem with Gnome browser Epiphany:
When I use the smiley method in my .css, I get this message in dreamweaver:
"The document's current encoding can not correctly save all of the characters within the document. You may want to change to UTF-8 or an encoding that supports the special characters in this document"
Then when I reopen the file my smiley face is now a question mark.
Even when I declare this at the beginning of the css:
@charset "utf-8";
it still won't save with the smiley. Any ideas?
@Morgan
I think somewhere else in Dreamweaver you can set which encoding you want to use…
To be honest, your file will be fine if it goes out the door with a ? mark..
Shrug.. dreamweaver is weird.
Hi,
On IE7 users always get a security warning. Any way around that? Can we target IE7 out and use sifr for them?
-Chris
@Chris Lambacher
I mentioned this guy in my Gotchas roundup post
http://paulirish.com/2010/font-face-gotchas/
It's due to IE security settings set to High. Only users (or companies) that have set their IE security settings to the High preset will experience this permission warning. There is nothing you can do about it other than not use @font-face. There is no way to detect it.
Thx a lot !!
It has been hard but it's done !! I'm on walkway bold thanks to you !
aby
Really great article,
but the smiley way doesn't work when you use iso-8859-1.
Got one for you all.
In Opera 10.60 build 3445 the @font-face works fine…
until I refresh the page and the text goes back to system fonts.
if I press enter on the address bar it comes back, but any amount of refreshes always gives system fonts and the address bar gives @font-face fonts. weird huh.
forgot to say in I.E. it works fine on refresh and with @font-face.
in firefox it works fine on refresh and with @font-face.
In IE and firefox it works fine.
10.61 the same
hello,
I want You all to know that the @font face generator have and error.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: demo_data
Filename: views/downloadable_demo.php
Line Number: 58
I cant generate a @font face.
Thanks the generator is so helpful.
Hi Sir, I just want to ask for any help or advice with regards on how to make my fonts appear.
I followed every step in the above mentioned post. But it doesn't seem that I am getting it all right.
I don't know much of HTML and CSS so i tried to copy formats from several websites including yours that uses embedded fonts.
I would really appreciate your help. Thanks.