Forcing anti-aliasing using css: Is this a myth?

CssFonts

Css Problem Overview


Recently a client has complained about the appearance of a system font in IE6. Basically th issue is that IE6 doesn't support font-smoothing/anti-aliasing (I know you can turn it on in an OS setting or something). But someone threw out this gem:

"You can force font anti-alias in css by using pt instead of px."

I did a quick POC in various browsers and saw no difference. I found one reference to it online, last post on this forum:

http://www.webmasterworld.com/css/3280638.htm

This sounds like the equivalent of a web developer urban myth, my feeling is it's BS. Has anyone ever encountered it?

Css Solutions


Solution 1 - Css

Oh yes you can:

-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-smoothing: antialiased;

Source for Firefox, thanks Justin for the heads up.

Solution 2 - Css

There's these exciting new properties in CSS3:

font-smooth:always;
-webkit-font-smoothing: antialiased;

Still not done much testing with them myself though, and they almost definitely won't be any good for IE. Could be useful for Chrome on Windows or maybe Firefox though. Last time I checked, they didn't antialias small stuff automatically like they do in OSX.

UPDATE

These are not supported in IE or Firefox. The font-smooth property is only available in iOS safari as far as I remember

Solution 3 - Css

No, there's not really any way to control this as a web developer.

Small exceptions are that you can do some fake forcing of anti-aliasing by using Flash through http://www.mikeindustries.com/blog/sifr/">sIFR</a>;, and some browsers won't anti-alias bitmap/pixel fonts (as they shouldn't, more info: http://daringfireball.net/2003/03/antialiasing">Anti-Aliasing</a> / http://daringfireball.net/2003/03/antiantialiasing">Anti-Anti-Aliasing</a>;).

Also, as Daniel mentioned, it's ideal to be using em units for all fonts, see http://jontangerine.com/log/2007/09/the-incredible-em-and-elastic-layouts-with-css">The Incredible Em & Elastic Layouts with CSS for more information about this.

Solution 4 - Css

I found a really awkward solution using the zoom and filter ms-only properties Example (try with no aa, standard and cleartype): http://nadycoon.hu/special/archive/internet-explorer-force-antialias.html

How it works:

-zoom up text with zoom:x, x>1

-apply some blur(s) (or any other filter)

-zoom down with zoom:1/x

It's a bit slow, and very! memory-hungry method, and on non-white backgrounds it has some slight dark halo.

CSS:

.insane-aa-4b                  { zoom:0.25; }
.insane-aa-4b .insane-aa-inner { zoom:4; }
.insane-aa-4b .insane-aa-blur  { zoom:1;
  filter:progid:DXImageTransform.Microsoft.Blur(pixelRadius=2);
}

HTML:

<div class="insane-aa-4b">
<div class="insane-aa-blur">
<div class="insane-aa-inner">
  <div style="font-size:12px;">Lorem Ipsum</div>
</div></div></div>

You can use this short jQuery to force anti-aliasing, just add the ieaa class to anything:

$(function(){ $('.ieaa').wrap(
'<div style="zoom:0.25;"><div style="zoom:1;filter:progid:DXImageTransform.Microsoft.Blur(pixelRadius=2);"><div style="zoom:4;"><'+'/div><'+'/div><'+'/div>'
); });

Solution 5 - Css

Adding the following line of CSS works for Chrome, but not Internet Explorer or Firefox.

text-shadow: #fff 0px 1px 1px;

Solution 6 - Css

I disagree with Chad Birch. We can force anti-aliasing, at least in Chrome using a simple css trick with the -webkit-text-stroke property:-

-webkit-text-stroke: 1px transparent;

Solution 7 - Css

I say its a myth.

The only difference I've found between pt, px, and percent based fonts is in terms of what IE will scale when the Menu > View > Text Size > ?Setting? is changed.

IIRC:

  • the px and pt based fonts will NOT scale
  • percent based fonts scale in IE just fine

AFAIK:

  • The font anti-aliasing is mostly controlled by the windows setting for "ClearType" or in the case of IE7/IE8 the IE-specific setting for ClearType.

Solution 8 - Css

I think you got it a bit wrong. Someone in the thread you pasted says that you can stop anti-aliasing by using px instead of pt, not that you can force it by using the latter. I'm a bit sceptical to both of the claims though...

Solution 9 - Css

The px to pt fix worked for me on a site that uses a font from Google Web Fonts. On Win7 - IE8 it correctly fixed the lack of anti-alias rendering.

Solution 10 - Css

Using an opacity setting of 99% (through the DXTransform filters) actually forces Internet Explorer to turn off ClearType, at least in Version 7. Source

Solution 11 - Css

Here's a nice way to achieve anti-aliasing:

text-shadow: 0 0 1px rgba(0,0,0,0.3);

Solution 12 - Css

I doubt there is anyway to force a browser to do anything. It would depend on the system configuration, the font used, browser settings, etc. It sounds like BS to me too.

As a note, always use relative sizes not PX.

Solution 13 - Css

Seems like the most exhaustive solution can be found at http://www.elfboy.com/blog/text-shadow_anti-aliasing/. Works in Firefox and Chrome, although Firefox is not quite as effective as Chrome.

Solution 14 - Css

As a side note, Gecko and WebKit support the the

text-rendering

property as well.

Solution 15 - Css

Not a pure CSS but natively supported method without any font replacement hacks: Simply convert your font to SVG and place it higher(before WOFF or TTF) in @font-face order. Voila! Fonts are smooth now, because they're no longer treated as a font but an SVG shape which will be nicely smoothened.

Note: I noticed that SVG can weight more than WOFF or TTF.

Solution 16 - Css

I found a fix...

.text {
            font-size: 15px;  /* for firefox */
            *font-size: 90%; /* % restart the antialiasing for ie, note the * hack */
            font-weight: bold; /* needed, don't know why! */
        }  

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFriendOfFutureView Question on Stackoverflow
Solution 1 - CssRyan BrodieView Answer on Stackoverflow
Solution 2 - CssBaronVonKaneHoffenView Answer on Stackoverflow
Solution 3 - CssChad BirchView Answer on Stackoverflow
Solution 4 - CssbiziclopView Answer on Stackoverflow
Solution 5 - CssMattView Answer on Stackoverflow
Solution 6 - CssSalman von AbbasView Answer on Stackoverflow
Solution 7 - CssscunliffeView Answer on Stackoverflow
Solution 8 - CssDeniz DoganView Answer on Stackoverflow
Solution 9 - CssMattView Answer on Stackoverflow
Solution 10 - CssPekkaView Answer on Stackoverflow
Solution 11 - CssJason FogliaView Answer on Stackoverflow
Solution 12 - CssDaniel A. WhiteView Answer on Stackoverflow
Solution 13 - CssMatthew O'RiordanView Answer on Stackoverflow
Solution 14 - CssJbirdView Answer on Stackoverflow
Solution 15 - CssPawelView Answer on Stackoverflow
Solution 16 - CssJean-Philippe MartinView Answer on Stackoverflow