62

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?

FriendOfFuture
  • 2,608
  • 1
  • 21
  • 21
  • 6
    Probably the closest thing to this is that you can make IE stop using cleartype by using certain css properties, namely opacity.. but naw – meandmycode Apr 17 '09 at 19:17
  • 2
    This is an old question, and browser abilities have changed. Check out the answer below that mentions "font-smoothing: antialiased;" – Kevin Oct 11 '12 at 19:02

16 Answers16

51

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.

Community
  • 1
  • 1
Ryan Brodie
  • 6,554
  • 8
  • 40
  • 57
  • 2
    Firefox 25+ now has font smoothing in OSX: `-moz-osx-font-smoothing: grayscale;` See: http://stackoverflow.com/a/17927764/922522 – Justin Feb 21 '14 at 17:06
  • 1
    cannot find any doc about font-smoothing and chrome dev tool doesn't recognize it – snoob dogg Nov 13 '19 at 20:28
39

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

The Pragmatick
  • 5,379
  • 27
  • 44
BaronVonKaneHoffen
  • 1,902
  • 1
  • 21
  • 29
29

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 sIFR, and some browsers won't anti-alias bitmap/pixel fonts (as they shouldn't, more info: Anti-Aliasing / Anti-Anti-Aliasing).

Also, as Daniel mentioned, it's ideal to be using em units for all fonts, see The Incredible Em & Elastic Layouts with CSS for more information about this.

Chad Birch
  • 73,098
  • 23
  • 151
  • 149
  • 19
    This is somewhat offtopic, but I'm not a proponent in elastic/bulletproof CSS layouts. They exponentially increase the amount of work if you're trying for a true "zoom" effect on a complex layout, and all A grade browsers except for IE6 support actual page zooming. – FriendOfFuture Apr 17 '09 at 20:04
  • 4
    Note - there is another option called "cufon" that is an html5 font replacement that support AA and is easier then sIRF (in my experience) http://cufon.shoqolate.com – electblake Dec 01 '10 at 15:22
  • 21
    @Sasha, there aren't really words strong enough to express how much I disagree with you (and the six people who upvoted you) on this. Yes, layouts that work at a variety of font sizes are more work, there's no doubt about it. But there are now more screen resolutions out there than ever before, and by only catering to the default font size on your monitor you are abandoning everyone else, including users of mobiles, netbooks and tablets, to their fate. – thepeer May 03 '11 at 15:30
  • 1
    At the risk of veering further off-topic, there's a difference between elastic layouts and responsive layouts. Using ems instead of pixels doesn't really help with different screen resolutions. – Tamlyn May 21 '12 at 16:17
  • @RyanBrodie You're joking, right? You actually down-voted an answer that was perfectly valid THREE YEARS ago? And FWIW, your answer is still wrong because the OP was asking about IE6, which was a valid browser to worry about... THREE YEARS AGO! – Paul Walls Nov 06 '12 at 08:14
  • 4
    @RyanBrodie Wow... I was feeling punchy when I wrote that and honestly didn't expect a reply, certainly not one as considerate as yours. That was incredibly cool of you Ryan. – Paul Walls Nov 07 '12 at 22:57
15

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>'
); });
Josh Lee
  • 171,072
  • 38
  • 269
  • 275
biziclop
  • 14,466
  • 3
  • 49
  • 65
  • Has anyone tried/verified this? I tried the example link above in WinXP + Firefox 3.x and I'm not really seeing the desired AA effect. – electblake Dec 01 '10 at 15:21
  • It creates a blurry mess in the new IE9, so don't use it :) – biziclop Mar 17 '11 at 19:52
  • Pretty laggy but impressive solution :) – Flash Jul 25 '11 at 04:22
  • The basic idea is: blur the rendering, but with a very tiny blur radius (less than a pixel). It's no substitute for proper anti-aliasing/ClearType, and will likely just decrease readability. It will, however, fix some rather nasty font rendering problems when using bolder-than-bold weights. – Zenexer Sep 20 '13 at 18:48
8

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

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

Matt
  • 9,068
  • 12
  • 64
  • 84
  • 2
    What does this have to do with MS ClearType? – Tom Jun 21 '10 at 17:20
  • 2
    Excellent! This works for me. P.S. I did change the second pixel value to 0 so as to make the smoothing of the text even on all sides: `text-shadow: #fff 0 0 1px;` – Web_Designer Apr 10 '11 at 05:30
7

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;
Samuel Katz
  • 24,066
  • 8
  • 71
  • 57
3

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.
scunliffe
  • 62,582
  • 25
  • 126
  • 161
2

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.

Matt
  • 21
  • 1
2

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...

Deniz Dogan
  • 25,711
  • 35
  • 110
  • 162
1

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

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
1

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

text-shadow: 0 0 1px rgba(0,0,0,0.3);
Jason Foglia
  • 2,414
  • 3
  • 27
  • 48
0

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.

Pawel
  • 16,093
  • 5
  • 70
  • 73
0

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! */
        }  
0

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.

Matthew O'Riordan
  • 7,981
  • 4
  • 45
  • 59
0

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.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

As a side note, Gecko and WebKit support the the

text-rendering

property as well.

Jbird
  • 2,839
  • 1
  • 21
  • 28
  • Yes, but bear in mind that in some versions of Chhome, text-rendering: optimizeLegibility; causes all kinds of text-rendering problems (e.g. http://code.google.com/p/chromium/issues/detail?id=78529). Oh, the irony. – Olly Hodgson May 09 '12 at 10:16