Published in Brighton, UK

Clagnut

Heaven Devoid of Stars – a tale of cross-browser kerning

Over on the Fontdeck Blog I posted a Christmas List for Type Fans. Among the things of beauty listed was this print sold in the I Love Typography store.

It was designed by Stefan Hattenbach of MAC Rhino Fonts, and set in his Tarocco Bold. I love setting type (usually while Her Indoors is watching some rubbish on the telly), and Tarocco is available from Fontdeck so I thought I’d give this print a go. I’m pretty pleased with the result, but it wasn’t without its problems.

When you’re setting type at large sizes like this A2 print, a certain amount of hand kerning is involved, even if the font you’re using includes kerning instructions. (Kerning means nudging letters together or apart, so they look more evenly spaced). I wanted to kern the web text exactly as Stefan kerned his print text, which I did fairly successfully:


Left: My web layout; Right: Stefan’s print layout

The screenshot above-left was taken in Firefox 8 on a Mac. When I looked at the same page in Safari I was disappointed. The differences in letter spacing are small but clear:


Rendering in Safari

But wait! Of course Firefox on a Mac has kerning instructions turned on by default, but Safari needs text-rendering:optimizeLegibility to turn on kerning. So I duly added that property and got this result:



Left: Safari with text-rendering:optimizeLegibility; Right: With Firefox superimposed on top

Safari is now better, but it’s still different to Firefox. There is different spacing between the letters, most noticeable between the T and A of STARS in the final line. Why? Does Safari kern differently? To answer that question we need to look at the markup. Here’s that final line:

OF
<span class="kern1">
  ST
  <span class="kern2">
    A
    <span class="kern3">
      RS
    </span>
  </span>
</span>

I’ve wrapped a span around the word ‘Stars’ and relatively positioned it towards the previous word ‘Of’. Within ‘Stars’, I’ve nested two more spans. Note in particular that the first of those <span> tags splits the ‘T’ and ‘A’.

T-A kerning pair screenshot

The Fontdeck Tarocco webfont includes kerning instructions, so now let’s look at Tarocco Bold’s kerning table. We see that there is an instruction to move the A eighty units towards the T. That’s a big kern, as you might expect with such a character pair. What’s clearly happening in Safari is that it sees the <span> tag separating the T and A, and decides that these characters are no longer adjacent and thus should not be kerned. Firefox behaves otherwise – it kerns the character pair despite them being separated by a <span> tag.

For me, Firefox gets it right. I’ll concede the problems I came across are pretty niche, but I believe inline elements should be ignored when it comes to deciding on whether or not to kern adjacent characters.

Cross-browser success

Having said all that, I did manage to get consistent type setting across all modern browsers. The trick was turn off the font’s kerning instructions first, and then re-kern everything manually. The way to turn off kerning, in addition to omitting text-rendering:optimizeLegibility, is with the font-feature-settings property. There are two different syntaxes: the old Mozilla way and the newer CSS 3 way, so you’ll need to include all these lines to be sure:

-moz-font-feature-settings:"kern=0";
-webkit-font-feature-settings:"kern" 0;
-o-font-feature-settings:"kern" 0;
-ms-font-feature-settings:"kern" 0;
font-feature-settings:"kern" 0;

I should point out that, out of all the above properties, only -moz-font-feature-settings is actually supported, and that in Firefox 3.6 and above.

Here’s my final version

Takeaway

If you’re going to manually kern, make sure you turn off the font’s kerning instructions first, thereby ensuring a common starting point and consistency across browsers.

And as a final note, if you like the look of Tarocco Bold (know I do) then you’ll do well to check the Adfont Calendar today (19th December).

19 December 2011

§ Browsers · Typography · CSS techniques

13 comments

Previous

Related posts

Keywords

Machine tags

Comments

  1. 1

    Hey Rich, I think that this is a fantastic exercise. Great investigations into kerning and browser handling.

    That being said, something’s gone wrong with your layout. Looks like the poster is too narrow to contain the text.

    Matt Wiebe
    Matt Wiebe’s Gravatar
    19 Dec 2011
    17:32 GMT
  2. 2

    Looks OK to me in Firefox 8, Safari and Chrome (all on a Mac). Which browser are you using?

    Rich
    Rich’s Gravatar
    19 Dec 2011
    17:36 GMT
  3. 3

    I tested in all 3 of those, Mac OS X 10.7.2, with the same results. Here’s what I saw in Chrome: http://cl.ly/Cj5Q

    Matt Wiebe
    Matt Wiebe’s Gravatar
    19 Dec 2011
    17:54 GMT
  4. 4

    It seems it is not working on Windows, neither chrome nor Firefox but… it works fine on IE9 and 10! _

    MJ
    MJ’s Gravatar
    21 Dec 2011
    12:06 GMT
  5. 5

    I’m seeing the same rendering issues as Matt, again Chrome Safari and FF latest versions on Mac 10.7.2

    That aside, stellar work (see what I did there)

    Duncan Beattie
    Duncan Beattie’s Gravatar
    21 Dec 2011
    13:27 GMT
  6. 6

    I see the same problem as #3 in FF8 and Safari on OS X Snow Leopard

    Kris Bulman
    Kris Bulman’s Gravatar
    21 Dec 2011
    13:32 GMT
  7. 7

    Looks like on the iPad, I’m getting the same issue as Matt did for Chrome (and I’m seeing the same thing in Chrome as well 16.0.912.63 Mac running 10.6.8; FF 8.01 also showing the issue as is Safari 5.1.1).

    That said, splendid work on deciphering at least some of the browsers!

    ender
    ender’s Gravatar
    21 Dec 2011
    14:04 GMT
  8. 8

    I’m getting the same results as Matt Wiebe in Mac OS X 10.6.8 using Firefox 8.0.1, Safari 5.1, and Chrome 16.0.912.63.

    Ralph Brandi
    Ralph Brandi’s Gravatar
    21 Dec 2011
    15:48 GMT
  9. 9

    All fixed now. The web font link was incorrect.

    Rich
    Rich’s Gravatar
    21 Dec 2011
    19:54 GMT
  10. 10

    Fantastic work! Hey does this mean I can print it out and get the poster now it’s sold out? Hehe.

    As for the rendering problems, at first I saw the same look as Matt in his screenshot, but after a few seconds the proper view kicked in.

    Regarding kerning, I noticed Firefox on Windows started doing it automatically a while back, though I’ve only noticed it on the letter “T”. Alas they seem to be applying too much kerning, to the point the letter is shoved right up to the next one, which looks wrong. If they can properly kern all letters, that might be nice.

    Chris Hester
    Chris Hester’s Gravatar
    21 Dec 2011
    22:37 GMT
  11. 11

    Hello. i was testing its not working on Windows.

    sohbet
    sohbet’s Gravatar
    25 Dec 2011
    19:49 GMT
  12. 12

    Hi Richard!

    Thanks for nice words and playing around with my poster. I hope you had a bit of fun too, despite some of the tech problem?

    Cheers

    Stefan Hattenbach
    Stefan Hattenbach’s Gravatar
    9 Jan 2012
    21:06 GMT
  13. 13

    Looks like you had a fun exercise!
    The browsers really all seem to work now! Thanks for showing!

    Cheers, Katrin

    WEb Angels
    WEb Angels’s Gravatar
    11 Jan 2012
    00:46 GMT

Add your comment

Comments are now closed on this post. If you have more to say please contact me directly.

Outside interest

Top Referrers