PSD to HTML conversion PSD to HTML conversion PSD2HTML.com with over 300 professionals takes the designs to HTML and beyond

Code Snippet

Home » Code Snippets » HTML » Cufon 101

Cufon 101

1. Include the JavaScript for Cufón and the Cufón font

<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/TitilliumMaps.font.js"></script>

2. HTML

Normal tags

<h1>Business Solutions</h1>
<h2>Business Insurance</h2>

3. Tell Cufón to replace the fonts for the specified CSS selectors

<script type="text/javascript">
    Cufon.replace('h1, h2', { fontFamily: 'TitilliumMaps26L', hover: true });
</script>

4. Add JavaScript error handling in case there is an error loading

function handleError() { return true; }
window.onerror = handleError;

5. CSS

The font color, size and hover color is controlled via the CSS classes associated with the HTML element.

h1 {
   font-size: 50px;
   color: red;
}

Reference URL

Subscribe to The Thread

  1. Hi, I’ve used Cufon on certain types, but one issue ive faced is that different fonts render in different sizes, that is say a 36px arial would be much larger than the 36px for my cufon-induced font, so if someone has javascript disabled, then the site looks messed up.

    Any pointers on how to mitiage this? thanks.

    • Deane,

      Check out the ‘Special Cases’ section under
      http://wiki.github.com/sorccu/cufon/styling

      When cufon replaces your elements, you can apply special CSS only after cufon has replaced text.

      h1 {
      font-size:2em;
      }

      The way this works, if Cufon fails to apply itself then your default css for the item h1 should get 2em size.

      If Cufon succeeds, then you can make a rule like

      .cufon-active h1 { /* for Cufon.replace(‘h1′) */
      font-size: 3em;
      }

      so the cufon-rendered font is bigger.

    • Dennis

      yeah, don’t use that crap! Use web fonts instead, it’s just text.. jesus people go out of their way to screw up the internet! You can do worse than cufon though.. USE FLASH!

    • Don’t like

  2. Is there any code or hack to skip the effect of preloading for cufon ?

  3. Cufon don’t support Arabic..

    sure we’ll find solution..:-)

    • a7madgamal

      any luck with arabic enabled solution??

  4. @deane

    I would load cufon normally and then have a normal stylesheet with text the size you want it. Then I would have javascript load in another stylesheet that overrides the first stylesheet and has the font sizes you need when using cufon. That way, if javascript is disabled, they don’t load cufon or the stylesheet associated with it. they just load the normal stylesheet. However, if javascript is enabled, it will load the styles that override the normal styles and allow for the correct cufon font styles.

  5. Here’s an example:
    <code&rt;
    <script&rt;
     var file = document.createElement(‘script’);
     file.setAttribute(“type”,”text/css”);
     file.setAttribute(“src”,theFile.ext)
    </script&rt;
    </code&rt;

  6. Meisha

    Any way to get Cufin to load the replacement fonts without first flashing the un-replaced font in IE? I’m using Cufon, and it looks great in FireFox, but it’s unacceptable in IE because the page loads the “ugly” version first before Cufon kicks in with the pretty fonts. Does anyone know of a font replacement method that doesn’t do this? Thanks!

  7. Meisha

    Sorry, I meant Cufon not Cufin @~@

  8. It’s not the best idea, but there are flash font replacements…

  9. Hi,

    cufon is not working for Arabic character.
    could you please help me for this issue.

    Thanks

  10. In a wordpress template I have seen a HTML tag as . What does it mean?

  11. @heena and @wdalhaj

    I wrote a blog post about the The State of Arabic Webfonts it might prove helpful for what you are trying to accomplish. Cufon does not yet full support Arabic script.

  12. works great with .html files but does anyone know how to place the script so it’s working with a .hta file?
    it ain’t gonna work by simply renaming the file.
    best regards
    thomas

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~