Stuff & Nonsense Home

Where you’ll find designer, author and speaker Andy Clarke. The bastard.

Blogging And All That Malarkey

Font Unstack

Earlier this week, I wrote about the limitations of current CSS to bind font styling to the availability of typefaces. I mused that a clever person might develop a solution using Javascript.

And there’s the problem with CSS, right there. Different typefaces, even common ones, that have been designed with different x-heights, need different amounts of line-height. Calibri less than Verdana and different again to Arial or Helvetica. But CSS does not provide the facility to specify a varying line-height if a font in the stack is not installed, as it retains the same set line-height value for all typefaces specified in the font-stack.

What are your options today? Perhaps a Javascript solution such as FontAvailable that can test for font availability. If you’re handy with the jQuery, you could then append a class based on the result.

In response to my call out, Phil Oye has done just that by writing FontUnstack, a jQuery plugin to query your font stack and on detecting the first available installed font will append a class to any element.

FontUnstack is a jQuery plugin that provides a workaround for the CSS/browser limitation of not knowing which typeface in a CSS font stack is actually used on the client-side. It simply adds a class with the name of the installed font to your desired HTML element(s). From there, you use CSS to do something interesting with that new class name.

I'll be experimenting more with FontUnstack on this site in the next few days before I make it part of my every toolkit. I'll also contribute a set of example pages for the project. Until then, grab the FontUnstack code for yourself.

Oh happy day.

Leave your comment

Phillip Smith

May 8 2009 @ 05:02am #

Nice find. :-)

Luke Dorny

May 8 2009 @ 05:09am #

Tweeted.
Excellent stuff.

Ryan Roberts

May 8 2009 @ 05:31am #

Brilliant, will have to have a play with this.

Jason Robb

May 8 2009 @ 06:23am #

Thanks for sharing. This rocks!

Adam Ma'anit

May 8 2009 @ 08:37am #

Looking forward to testing it out.

Phil Oye

May 8 2009 @ 09:39am #

Everyone, let me know what you think. Send me any comments/bugs/issues/fixes. I’d love to what you come up with. Definitely looking for a jaw-droppingly awesome example file.

Dylan

May 8 2009 @ 10:40am #

Nice work Phil!

Commenting is not available in this channel entry.
Hardboiled Web Design

Hardboiled Web Design by Andy Clarke

How the latest technologies and techniques will make your websites more creative, flexible and adaptable. Get hardboiled in all formats from Five Simple Steps. Digital formats also available at Amazon.com, Amazon.co.uk and the iBooks store.

We’ve deconstructed this site to focus on content while we restyle. Expect wonkiness during the transition.