I’ve been playing with some design tweaks to this blog, as I’m prone to do, though in this revision I managed to enter into some advancements with newer browsers: namely, font embedding via the CSS @font-face directive.
Why this matters
The idea is that browsers now support the ability to download and incorporate fonts not on the host system. This is a big leap forward, because there is a very limited set of fonts which you can use for the web. Mac fonts aren’t all in Windows or in Linux installations, ditto for Linux into Windows, etc.
You can use CSS to have a list of fall-back font families, though all this does is allow for the particular system to use a different font which is “good enough.” Namely, you can have:
body {font-family:"Helvetica","Arial", sans-serif;}
which reads that the body tag should first utilize the Helvetica font; if Helvetica is not available, then use Arial; if Arial is not available, then use any sans-serif font on the system.
With embedded fonts, I can keep this same syntax yet with an additional font which isn’t necessarily on the visiting computer:
* {font-family:'Fontin', 'Helvetica', sans-serif;}
This says that for all elements, use the “Fontin” font first, then fall back in the same way as in the other example. Fontin is a free font which is publicly available and is released under terms which allow for embedding into a page. You can download Fontin at the exljbris Font Foundry website, and view a list of other fonts also available for this purpose at the webfonts.info wiki.
Making the font files findable: @font-face
So, if you have tried the above without more work, you’ll quickly see that nothing new is happening. The trick, then, is that the browser needs to know a bit more about this “Fontin” typeface which is not on the computer. Before the declaration of the font family in the CSS file, you’ll need to add something like this:
@font-face {
font-family: "Fontin";
font-weight:bold;
src: url(/fonts/Fontin-Bold.otf) format("opentype");
}
@font-face {
font-family: "Fontin";
font-style:italic;
src: url(/fonts/Fontin-Italic.otf) format("opentype");
}
@font-face {
font-family: "Fontin";
src: url(/fonts/Fontin-Regular.otf) format("opentype");
}
Hopefully this is mostly self-explanatory, though what’s a bit tricky at first is that there are multiple declarations for the same font. There’s also a src for each font file; so you’ll have to have these publicly accessible on your web server in order for the browser to download and utilize them.
Browser support: not all there yet
With the overloading CSS as above, both Opera and Safari under OS X fail a bit, instead rendering whatever is the last listed directive. In that case, it’s probably safest to list the normal font last, unless you want everything in italics, etc.
One way around this is to use different font-family names, and then re-define the CSS such that em tags and any other italicized text gets the alternate font-family definition; i.e., font-family:'Fontin-Italic', etc.
Firefox 3.5 works without a hitch, however, so hopefully this will just be reconciled with later versions of the other browsers. Internet Explorer doesn’t play game at all; my guess is that there are additional tweaks specific for IE, as is most alway the case.
Still, what’s great about the system is also what’s great about CSS: even lacking browser support for the latest iterations, your site will fall back to using the same fonts you had set up previously.
Proceed with caution: license considerations
One trick with this font system is that there are not all that many fonts available for this particular use. Most TTFs are not free, and even those that are free cannot necessarily be shared in such an open way. While this may seem a bit cruel on the part of the font foundries and font makers, using this system does require that the font files are open and unrestricted: it doesn’t take much work to look at the CSS files to find the web location of the fonts themselves, which then leads towards very easy propagation of the files without a requirement for attribution, etc.
Conclusion
The constant problem in being on the edge, especially with the web, is that it doesn’t always work out for every system. In terms of danger, however, setting alternate fonts does not seem to me to be all that dangerous. In the absolute worst case, the site will just display whatever is next in the CSS list of fonts. I personally am conservative in terms of utilizing new web technologies, though in this case I don’t see too much reason to hold back.