Font Replacement Using Cufón

By  on  
Sin City

We all know about the big font replacement methods. sIFR's big. Image font replacement has gained some steam. Not too many people know about a great project named Cufón though. Cufón uses a unique blend of a proprietary font generator tool and JavaScript to create a custom font renderer in canvas and VML. Here's how to use Cufón to render the Sin City font for your headers.

Step 1: Generate the Font

The first step is to use the Cufón font-generator tool to convert and customize the way the font renders. I was very impressed with the number of options available for the font conversion. Once the conversion is done, Cufón's generate presents you with a JavaScript file containing the font information as Cufón can read it.

Step 2: Include Cufón and the Font

Include the Cufón JavaScript file and the generated font's JavaScript file.

<script type="text/javascript" src="cufon.js"></script>
<script type="text/javascript" src="Sin_City_400.font.js"></script>

Step 3: Selectors and Elements

Time to select the elements to Cufón-ize. I don't recommend using Cufón for every bit of language on the page -- doing so can be resource-intensive. Generally you want to use custom fonts in headings so that's what I've chosen to do below.

Cufon.replace('#cufon-area h1, #cufon-area h2, #cufon-area h3');

In my experience, Cufón looks better than both sIFR and image methods. Be sure to check out Cufón as it's an outstanding tool and I look forward to seeing where the project goes. What are your thoughts?

Gentlemen...you're welcome for the gratuitous Jessica Alba image.

Recent Features

  • By
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

  • By
    Chris Coyier&#8217;s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

Incredible Demos

Discussion

  1. Cufon’s great, the only dealbreaker is: no selectable text! sIFR provides that and to me that’s really a big factor in the font replacement decision making.

  2. I use Cufon on my site, but there are a couple of limitations/problems:

    1) As @wink said – there’s no selectable text – but they’re working on that

    2) Screen readers have a bit of a spaz when reading out the replaced text as each word is surrounded by a So. It. Reads. Each. Word. As. If. It. Was. A. Sentence.

  3. Hirvesh

    Great Cufon Review! You might also find this resource interesting, it list 5 image replacement techniques, including cufon.

    5 Image Replacement Techniques For Custom Font Embedding

  4. The only problem at this point, with whatever method of font replacement, is the licensing. Before using any font on a website, it’s important to check whether public use is allowed.

    Cufón is good in this respect because it allows you to limit the font to a certain domain, but there’re still some issues with using a font face legally.

    Just fyi. It’s not like using it on a personal site will break the bank either way. :)

  5. As a programmer, someone who doesn’t worry about font licensing and such, I think font licensing and all that sucks. I’d go as far as saying that it’s holding the internet and web design back.

    • IANAL, but I have read a fair bit on copyright law, and as I understand it, copyright law does NOT extend to fonts. I believe a court ruling said something to the effect of “you can not copyright the alphabet”. So while I agree with CreativeNotice that font designers have the same right to get paid for their work that the rest of us do, legally I don’t believe they can actually enforce any licensing.

      Of course, IANAL, YMMV, consult an attorney, do not operate while wet, etc.

    • Vic Blade

      Great Solution! It does not seem to work in Firefox 11 for Mac. The Sin City page had some pretty normal looking H1 and H2 tags until I viewed it in Safari.

      Thanks, you site is a great resource that we always refer to.

  6. yeah, I already knew bout cùfon but
    it sux, cuz u cant’t select the text, and this could b a really frustrating xperience for the users.

  7. Cufon is really awesome. I actually used it for a day on my blog, but it was 38kb of Javascript (minified, not gzipped) so I could replace 3kb of images. Not worth it yet unless you have a good amount of text to use it on.

    Also, totally agree with you about licensing David. It’s BS.

  8. While font licensing is a pain, I understand it’s use. Designing a decent font is hard work; I’d want to be paid for it too.
    I’ve yet to meet a headline that couldn’t be handled with an image+text+text-indent: -999em; So the only use I would have for sIFR or Cufón is in a CMS application where the headline content was unknown.

    Very interesting to watch though. Anyone care to change my mind on sIFR and Cufón?

  9. Looks very great, i didn’t know it, thanx.

    I discovered another great tool, typeface.js while i was coding my girlfriend’s photoblog, it provides selectable text but, sadly, it’s not cross-browser.

  10. Not bad… Unfortunately a bit large for me. I would prefer something smaller in size. Anyway… good

  11. Funny how far we need to go for custom fonts, huh?

  12. This is my preferred method for font replacement, too. Much easier than the others I have tried (sIFR and FontJazz). Using it on my personal site without (WordPress install), and couldn’t be happier with it.

  13. I decided that I won’t be using sIFR or Cufon in my projects anymore, they are slow, and cause content jumps after domready, which is really annoying if the visitor has already begun reading text.

    I will wait for the css3 font face property to become mainstream before I would consider using custom fonts again.

    Then again, I’m talking about mainly heavy content driven sites, and not highly graphical sites, which might require a fancy font here and there.

  14. Actually, you can select (and copy/paste) Cufon text. You won’t be able to see your selection over the ‘Cufon-ed’ text, but try it – it works.

    Granted, the average user (and indeed it seems, most people) don’t realise, but the text is still there.

  15. The unique problem in this method is for a device that not suport CSS. The words in the title, in this example, is showing twice. It´s no so good.

  16. KC

    Thanks for the tutorial but I’ll certainly wait for CSS3 support for font-embedding.

  17. I actually tried this yesterday, but it didn’t work with Chrome or Safari.
    But your magical demo is working.

    Did you do anything special to make it work?
    I followed the tutorial on their website, but could get it to work for those 2 browsers.

  18. Hi,

    Me and my colleagues have made a direct test between jQuery SIFR – http://jquery.thewikies.com/sifr/ and Cufón http://wiki.github.com/sorccu/cufon/usage.

    Disadvantages of Sifr are advantages of Cufón :):

    bad browser stability
    does not take into account the width of the parent div
    in certain cases may occur horizontal scroller
    for a bold font you need a new .swf
    does not take into account line-height or any other HTML tag

    In both cases, the web bots can see the page as html document. Replacement is performed on the client side when the page is already loaded.

    Our live test is on http://www.intera.si/intrix_crm. It works in all major browsers…I hope :)

    @Ian Oliver: Cool! I did not know that this works :)

  19. Very nice job Andrej!

    cufon, sifr: they both generate text dynamically so I, personally, have no problem to use any of them!

  20. Dan

    What about printing a page that has fonts rendered with Cufón or sIFR?
    I tried printing some demos made with them and I only got the simple html.

  21. Dan

    my mistake, actually, sIFR generated fonts print exactly as on screen.

  22. rpflo

    I love cufon. Unfortunately, my favorite fonts don’t allow it in the license.

    • Kevin

      Do you know of any comprehensive list of usable typefaces? It’s a grind sorting through the legal jargon in EULA.

  23. Srinath

    Its Awesome man..

  24. squidz

    @David Walsh: Using fonts that are not “open-source” beyond the license offered by the manufacturer/designer is the same as someone using your proprietary code, your photography, illustration, written word, music, etc., without your permission. It’s a drag, but a legit issue for those that design and produce fonts for a living and there isn’t one bit of difference between fonts and those other items mentioned above.

    On the other hand, if the actual font file is/can be protected, I see the use being the same as when I use fonts in print design. The font is viewable, my client gets to “use” it in their promotional print material, but the (digital file) is not there for the taking by the viewer/reader of the piece.

    Just like artists and musicians, these issues are morphing with technology. Font producers will have to roll with it as well, especially if embedded fonts hit CSS.

  25. D

    Why did you steal the facebook design? Kind of oogly for a web design resource site.

  26. Selectable text seems like a big issue for Cufon at the moment, however, for some reason Firefox in Linux (Ubuntu Karmic) seems to allow you to select the text – and copy/paste it correctly.

    I wonder why? Any ideas?

  27. This is a great little tutorial! Your “View Demo” isn’t working though. No problem.

  28. Tufan

    Cufon font library: http://www.cufonfonts.com/

  29. Awesome! Dosent work in IE7 just show blank is there any updates for this??

  30. Sky

    Doesn’t work on my Firefox

  31. Thanks a lot!
    It works like a charm :D

  32. Cufon:
    Missing features
    Text selection: until we find a solution that works in Opera, this feature will not be added. We have solutions for other browsers.
    try Typekit + Cufon, Typekit is a hosted, @font-face-based> alternative, and it support text selection.

  33. Subbaiyan

    how to multiple font use in single site in

    this type of methods

    Cufon.replace('#siva, p');

    sorry i don’t have very well English knowledge

  34. Subbaiyan

    i will used this type of script font method its working well but how to use multiple font used in single page cufon method

    • Prawin

      Just generate another font js file and use it same way as instructed.

  35. Cufon is very slow

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