Font Smoothing in Webkit and Firefox

By  on  

I don't pretend to be a typography or design expert -- I just know what looks good and what doesn't.  A few years ago I saw a few CSS properties I didn't recognize and when I toggled them on and off, the text went from beautiful to...not so beautiful.  It was a welcome to the world of font smoothing.  I recommend reading this post to learn more about what font smoothing is, but in this post I'll give you the CSS properties and values you need to know:

body {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

The difference in font presentation with and without font smoothing is fairly significant:

With smoothing: Font Smoothing - With

Without smoothing: Font Smoothing - Without

The difference is subtle but usually eye-pleasing and softer. When you go about picking custom fonts for your next website, try to experiment with font smoothing -- it may have a large effect on content readability!

Recent Features

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

  • By
    From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!

    My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...

Incredible Demos

  • By
    Custom Scrollbars in WebKit

    Before each of the browser vendors we like was providing unique CSS controls, Internet Explorer was setting the tone.  One such example is IE's early implementation of CSS filters. Internet Explorer was also the first browser that allowed developers to, for better or worse, customize...

  • By
    GitHub-Style Sliding Links

    GitHub seems to change a lot but not really change at all, if that makes any sense; the updates come often but are always fairly small. I spotted one of the most recent updates on the pull request page. Links to long branch...

Discussion

  1. Thanks for sharing. Is it support for all kind of browsers?

    • No, this would be only supported on the browsers in Apple OS platforms.

  2. Luis

    Hello David,

    You are using lossy jpg files for the example images, which blur around the edges of the text. That renders the font comparison less realistic.

  3. Thank you so much! I could never figure out why my site looked so much worse on Firefox than Chrome. Added this to my body CSS and now they look the same!

    • Jason

      Same with me! Thank you for sharing David

  4. Thanks for sharing this! Making fonts look good, readable and beautiful is half the battle won, when setting up a web page.

  5. Hey, what’s the best way to achieve div elements swapping/reordering? I have div1, div2 and div3. I’d like them to be 2,1,3 on mobile. Thanks.

    • flex order is your friend.

  6. Chris

    Messing with font aliasing is bad, it may look good on YOUR computer, but turns out even worse than before on other people’s computers.
    This is most apparent when you’re going from one OS to another, where fonts are different even when using the same font name.

    Think twice before you’re going to do this, especially when it’s browser prefixed only and not part of a standard yet.

    • James

      “… where fonts are different even when using the same font name.”

      They shouldn’t be, unless you’ve made a mistake when declaring the typefaces, or have a local font by the same name that differs in appearence.

      The idea of this AA fix is that it ADDS consistency, it doesn’t remove it. If you know of a browser/OS combination where adding font-smoothing in this way has a detrimental effect then please share your information.

  7. David hi,
    I’m experience the same problem with images in other browsers except for chrome, my images are great in chrome (bkz:logo) but in ie or firefox my problem is like font problem that you’re talking about, do u have any idea or experience to fix it, ha ?

    Thanks for this great sharing.

  8. Michael

    When you say “without smoothing” do you mean “with font smoothing turned off” or “without setting the font smoothing property?” When you don’t set the font-smoothing property, that doesn’t mean font smoothing is off. It lets the browser decide what is best, and it usually uses sub-pixel antialiasing. If you hard-code a value, it’s important to test a wide variety of operating systems and pixel densities, as you could be making things much worse for people who happen to be using a setup that isn’t exactly the same as yours.

    • dhwang

      Actually default is subpixel-antialiased, so antialiased is still applied even when you’re not specifying this. It’s just different scheme and subpixel-antialiased produces thicker looking font.

  9. Maybe it’s my eyes but I don’t see any difference in Chrome on my Ubuntu box.

  10. Flip

    I. LOVE. YOU. I am a graphic designer who develops websites for about a year now and always had trouble with the firefox displaying fonts too strong. This safed my life and makes my websites look as they alway should look like. Thanks a lot dude. You are awesome!

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!