treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] @font-face rendering issue in Chrome for PC

  • I used font-squirrel to embed a font onto a site (with Apply Hinting selected), and it's not rendering properly in Chrome v15.0 for PC. The font shows, but poorly. I'm sure that font-squirrel gave me the right code, so I assume there is a conflict in my CSS. Thanks in advance for your help.

    Screenshot

    Link to site

    @font-face {
    font-family: 'RockwellStd-Light';
    src: url('rockwellstdlight-webfont.eot');
    src: url('rockwellstdlight-webfont.eot?#iefix') format('embedded-opentype'),
    url('rockwellstdlight-webfont.woff') format('woff'),
    url('rockwellstdlight-webfont.ttf') format('truetype'),
    url('rockwellstdlight-webfont.svg#RockwellStdLight') format('svg');
    font-weight: lighter;
    font-style: normal;

    }

    h1 {
    font-family:'RockwellStd-Light', Helvetica, Ariel;
    font-size:34px;
    color:#407d3b;
    font-weight:lighter;
    margin-left:20px;

    }

    h2 {
    font-family:'RockwellStd-Light', Helvetica, Ariel;
    font-size:32px;
    color:#ece1af;
    font-weight:lighter;
    line-height:42px;

    }

    h3 {
    font-family:'RockwellStd-Light', Helvetica, Ariel;
    font-size:20px;
    color:#FFF;
    font-weight:lighter;

    }

    p {
    font-family:'RockwellStd-Light', Helvetica, Ariel;
    font-size:14px;
    line-height:17px;
    color:#333;
    text-align:justify;

    }

    .criteria_table {
    font-family:'RockwellStd-Light', Helvetica, Ariel;
    font-size:14px;
    color:#FFF;

    }
  • The rendering looks fine to me.
  • I've added a link to a screenshot above
  • Yup, that's how Chrome renders the font, unfortunately.

    Give this a read: http://blog.typekit.com/2011/01/26/css-properties-that-affect-type-rendering/

    You could try seeing if using -webkit-font-smoothing: antialiased; helps at all.
  • No luck with -webkit I'm afraid. Also no luck with the text-shadow hack
  • SOLVED: by adding text-shadow with these values


    text-shadow: 0 1px 0 rgba(0,0,0,0.01);
  • @Rockomole This is odd because I'm still seeing the issue. I'm using Rockwell Std-Light on my site as well however, I'm not getting this issue. I'm wondering if it's the way you're embedding it. What I get on my site is the same shown here.
  • try removing the font-weight property in the css selectors rules. You can leave it for the @font-face but will not need it unless you have more @font-faces with the same name. It is not needed in the css tags selectors since you are calling the only font family with that name and it is already a ligher font...so defining font-weight is not needed.

    Not saying this will cure the issue but worth a shot.
  • I came across a better solution recently, so just wanted to update it here :)

    Add this as a new CSS rule after the @font-face rule

    @media screen and (-webkit-min-device-pixel-ratio:0) {
    @font-face {
    font-family: 'FONT-NAME';
    src: url('RELATIVE-FONT-URL') format('svg');
    font-weight: normal;
    font-style: normal;
    }}
  • If any of you are still looking to improve your webfont rendering in Chrome, you may want to take a look at this post on our blog. It does have a solution similar to @rockomole's suggestion: http://www.fontspring.com/blog/smoother-web-font-rendering-chrome
  • I recently read that John Hoefler reported a bug in Chrome that has to do with rendering fonts. Not sure what exactly it consists of - still waiting to hear back.

    Edit: It's unrelated.
  • Chrome was cutting my icons in half. IE wasn't working because of a bad woff conversion. Another long day.

    Paul Irish's worked for me:


    @font-face {
    font-family: 'MobileIcons';
    src: url('MobileIcons.eot');
    src: url('MobileIcons.eot?#iefix') format('embedded-opentype'),
    url('MobileIcons.svg#MobileIcons') format('svg'),
    url('MobileIcons.woff') format('woff'),
    url('MobileIcons.ttf') format('truetype');
    }


    And I found this link, so watch out for sneak Arial attacks:

    http://sixrevisions.com/css/font-face-web-fonts-issues/
  • None of the above work, sorry. I am using Drupal CMS and all my sites have fonts [both @font-face and standard body text] that are bleeding out around the edges in Chrome only, any suggestions?

  • Just tried: -webkit-text-stroke: 1px transparent but no luck. The link is, http://majellagt.com.

    Thanks

  • @cherie What text exactly are you having issues with? It's hard to debug since you're code is inline styled. Have you tried the following:

    -webkit-font-smoothing: antialiased;

  • Ok, so i have now tried:

    -webkit-font-smoothing: antialiased;
    
    -webkit-text-stroke: 1px transparent ;
    
    @media screen and (-webkit-min-device-pixel-ratio:0) {
    @font-face {
        font-family: 'ResagokrLight';
       src: url('../fonts/ResagokrLight-webfont.eot');
        src: url('../fonts/ResagokrLight-webfont.eot?#iefix') format('embedded-opentype'),
           url('../fonts/ResagokrLight-webfont.woff') format('woff'),
           url('../fonts/ResagokrLight-webfont.ttf') format('truetype'),
           url('../fonts/ResagokrLight-webfont.svg#ResagokrLight') format('svg');
    font-weight: normal;
       font-style: normal;
    }}
    
    text-shadow: 0 1px 0 rgba(0,0,0,0.01); 
    

    So far all areas that i have applied it h1, h2 etc and body still do not render the fonts correctly. Even the standard font family:

    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    
  • I am using a mixture of:

    -webkit-font-smoothing: antialiased;
    -webkit-text-stroke: 1px transparent;
    text-rendering:optimizeLegibility;
    

    While its not perfect, it is a lot better

  • @cherie From what I've read, you cannot use @font-face inside Media Queries (some bug issue).

    Edit: The bug causes a few browsers not to display the font.

    It could be the optimization of the font itself so why don't you take a screenshot and upload it to http://tinypic.com and paste the URL here so I can take a better look.

  • Have you tried this? I'm not sure exactly why, but this has worked for me various times:

    
    
    @font-face {
          font-family: 'ResagokrLight';
        src: url('../fonts/ResagokrLight-webfont.eot');
          src: url('../fonts/ResagokrLight-webfont.eot?#iefix') format('embedded-opentype'),
            url('../fonts/ResagokrLight-webfont.woff') format('woff'),
            url('../fonts/ResagokrLight-webfont.ttf') format('truetype'),
            url('../fonts/ResagokrLight-webfont.svg#ResagokrLight') format('svg');
      font-weight: normal;
        font-style: normal;
    }
    
    @media screen and (-webkit-min-device-pixel-ratio:0) {
      @font-face {
            font-family: 'ResagokrLight';
            src: url('../fonts/ResagokrLight-webfont.svg#ResagokrLight') format('svg');
            font-weight: normal;
            font-style: normal;
    }}
    
    
  • @rockmole Why would you set @font-face twice with the same font format?

  • Not sure to be honest :P I came across it in another forum some time ago and decided to give it a shot. My fonts then started rendering fine in Chrome. It's possible that it's not bulletproof, but from my tests (on Browserlab and on various friends computers) this seems to work well.

  • Remove the media query and it should still work.

  • Without the media query it won't render aliased on Chrome for PC. Here are screenshots I just made. Right shows it with media query included, left without.

    Screenshot

    These were taken from Browserlab, but I've seen the same directly from a PC. I'm baffled as to why this should work, but it seems to be doing the trick.

    I'd post a link to the forum where I found this, but I can't find it anymore :/

  • *antialiased

  • @rockmole use -webkit-font-smoothing: antialiased;

    and if that doesn't work, move the SVG version above the woff.

  • By the way, did you convert that font using Font Squirrel?

  • I'm afraid -webkit-font-smoothing has no effect in Chrome PC, and moving SVG above WOFF makes the font fail to load (FF & Safari mac)

    and yeah, I used font-squirrel's code generator

  • @Rockmole That's weird. Sometimes messing with the settings can have an effect on the outcome of converting the files. If you didn't, I bet it's just due to not being optimized properly.

  • From what I've read, it's a recurring problem with Chrome. It struggles to render a lot of fonts properly, if not all (even Google fonts, ironically). I'd put my money on Font-Squirrel's optimization being right and that Google needs to do some work on Chrome...

    Why is it that @font-face shouldn't be in media queries?

  • It depends. When it comes to webfonts there is a list of things that can cause issues. Google's webfonts are not optimized for screen use. They are poorly hinted.

    There's a bug when putting @font-face in media queries. I can't recall if it only effects the iPhone or webkit based browsers.

  • The problem with Chrome for Win is the font rendering/smoothing engine. It does not work well with WOFF or TTF files. For instance, on this website: http://goo.gl/Y5hSu you'll see they have a standard FontSquirrel-esque @font-face rule. However, for some reason, the WOFF file is not being served. Either it's just not there or they haven't configured a MIME type for it and their server is rejecting it. Either way, the WOFF file isn't available for their web font and in Chrome for Win the fonts look great, antialiased and smooth. That's because Chrome is using the SVG font since it can't find the WOFF file. The SVGs probably use a different rendering engine that the fonts.

    That's why, adding an extra @font-face rule AFTER your first one with just the SVG source will override the original one if the browser supports SVG fonts at all.

    You might try experimenting with your original @font-face rule and see if placing the SVG source last in the list works as well. So you could try this:

    
    @font-face {
          font-family: 'ResagokrLight';
        src: url('../fonts/ResagokrLight-webfont.eot');
          src: url('../fonts/ResagokrLight-webfont.eot?#iefix') format('embedded-opentype'),
            url('../fonts/ResagokrLight-webfont.woff') format('woff'),
            url('../fonts/ResagokrLight-webfont.ttf') format('truetype'),
            url('../fonts/ResagokrLight-webfont.svg#ResagokrLight') format('svg');
      font-weight: normal;
        font-style: normal;
    }
    @font-face {
            font-family: 'ResagokrLight';
            src: url('../fonts/ResagokrLight-webfont.svg#ResagokrLight') format('svg');
            font-weight: normal;
            font-style: normal;
    }
    
  • @thetrickster

    I have to say that worked to smooth the font in chrome (Win7) however then suddenly firefox is showing errors by not showing the icons but numbers (wich the icon is attached too inside the font)

    Another thing wich i don't understand is that when using icomoon app when i download my font and insert it it works on Chrome, IE and Safari. However it doesn't work in Firefox and Opera it will show the numbers only. But when i choose base64 in the icomoon app and then implent it into my files it works on all browsers. But then smoothing will not work in Chrome and Opera.

    This is very annoying, when you think you finally got it, it's ruined in a for ex. Firefox or opera etc. etc.

    EDIT:

    Finally i figured it out. you will need to make sure that chrome is using SVG (i think it does to smooth the icons) however when i did that the icons in firefox would disappear because (i think) firefox can't use svg icon fonts.

    
    @font-face {
    font-family: 'fontname';
    src: url('fonts/fontname.eot');
    src: url('fonts/fontname.eot') format('embedded-opentype'),
    url('fonts/fontname.svg#fontname') format('svg');
    }
    
    
    /*if mozilla*/
    @-moz-document url-prefix() { 
        @font-face {
            font-family: 'fontname';
            src: url('fonts/fontname.ttf') format('truetype');
        }
    } 
    

    Source

    So firefox will use the ttf format and chrome will use the svg format that way the font is smooth on all browsers. Except Opera that one is still not showing the icons.

    EDIT2: Make sure you have the following at the end of the svg font: #fontname

    
     url('fonts/fontname.svg#fontname') format('svg'); 

    That will make it work in Opera, every icon-font will be smooth on all the browsers

  • SVG's aren't suitable for small sizes as they are basically scalable images and not actually a font. And therefore the hinting data is lossed making the fonts render just as poorly on Windows. PostScript fonts can solve the aliasing for display faces. I believe Typekit does this for some fonts in their library. Webtype is manually optimized for a range of font sizes so they generally render really well.

  • I'm having a similar yet different program. When I view a font I'm using (*Caviar Dreams Regular also from Font Squirrel ) - it renders the same on my PC and Mac in all browsers.. BUT on a co-workers computer, it's actually bolder. And we're looking at the same site and url. Any ideas on why it's different?

  • What's the difference between their computer and yours?

  • They should be the same - both are Mac Book Pro's -- same browsers versions being tested. Not sure.. Got any ideas of what to look for?