Render Text With Javascript: Typeface.js
Author: Stefan Vervoort | Please Comment!More and more alternatives for CSS typography are seeing daylight and that is great news for the webdesigner who would like to have some more typography options on the web.
Recently I have written tutorials about the use of sIFR3 and FLIR. Check them out if you like. Today it is time to teach you something about a technique I have just discovered. Today you will learn how to use typeface.js.

Basic information about typeface.js
Typeface.js is a JavaScript library that adds the possibility to choose from fonts that aren’t installed on your visitors’ computer. The JavaScript transform basic HTML and CSS to images with your custom font. Typeface.js is developed by David Chester, and I am sure we will see many more features for typeface.js in the future.
Cross-platform
Something that is really great about this technique is that it works in most browsers like Internet Explorer 6+, Firefox 1.5+ and Safari 2+, and if typeface.js is not supported by an older browser, it will degrade gracefully. No problems for the visitor: they will not notice they are missing the fun.
Search Engine Friendly?
One of the most important things about these kind of techniques is the search engine friendliness. If that’s not the case, we aren’t able to use it because it’ll hurt our search engine results.
Fortunately, typeface.js is very search engine friendly. You write just normal HTML and CSS, so the search engine can still know what your content is all about.
Advantages of using Typeface.js
I feel that this technique has many advantages and with some more development this can really turn into the perfect alternative to SIFR3.
Simple to use - The advantage above SIFR3 is that it is more easy to install and use.
Light-weight - You shouldn’t use typeface.js for whole paragraphs, but when you use it for headings or titles, typeface.js loads faster than alternatives like SIFR3 or FLIR.
No flash, No PHP, just JavaScript - The alternatives use PHP or flash to render their text. Typeface.js is only a piece of JavaScript.
Select your text - Although it isn’t as developed as one could wish, the option exists to select and copy text. You just need to select the text as usual and copy and you will have the text copied. The problem with this is that you can’t see what you’ve selected.
Installation to your website
After this introduction it’s about time to start installing and using typeface.js. You need to start with downloading the JavaScript library and place it somewhere in your site. I recommend you make a special folder called js to store all your JavaScript files.
Converting a font
Next we need to convert a TrueType font to a JavaScript file. We can do that by using the converter on the official site. Click here to visit the generator.
Choose your TrueType font file from the /WINDOWS/fonts folder on Windows. In a Mac you can find them here. Please keep in mind that you might not have permission to use every font you have installed, so check that out first. If you have your font converted and downloaded, copy the YOURFONT.typeface.js file in the same folder with your typeface.js.
Tip: If you can’t select your TrueType font from inside the /WINDOWS/fonts folder, try copying your file to another folder.
Implanting Typeface.js in your website
Now our preparation is done and we can start implanting the files into your website.
External CSS file - You will have, most likely, an external stylesheet in place. The next step is implanting the JavaScript files and it is really important to load your external stylesheet before the JavaScript.
Implant your external CSS file like this:
<link rel="stylesheet" type="text/css" href="stylesheet.css">
Implant the JavaScript - Next we will add the typeface.js library and the typeface.js fonts to our site. Here are the codes:
<script src="js/typeface-0.10.js" type="text/javascript"></script> <script src="js/YOURFILE.typeface.js" type="text/javascript"></script>
The YOURFILE.typeface.js is the font you have converted earlier.
Using in your website
Using typeface is very easy, you only have to do some basic HTML and CSS.
<div class="typeface-js" style="font-family: YOURFONT"> Typeface.js will convert these lines of text to YOURFONT. </div>
You have to add the class typeface-js to the element your text will need to show. If you already used a class on that element, simple add more:
<div class="class another-class typeface-js"></div>
The inline style declarations aren’t the perfect solution, but I guess that will be solved in future versions of the typeface.js library. You should replace YOURFONT with the name of the font you used when converting your TrueType font.
Mission Accomplished
That’s right, that’s all it takes to implant typeface.js in your site or blog.
I have created an example for you and I have did that in 1 minute. It is really that easy! Click here to view my example or here to view the developers example.
You want more Typeface.js?
I suggest you take a look at some of the links below for more information.
- Developers Homepage
- Dafont - For free fonts
- Examples










Loading...
2:59 am on November 3rd, 2008
I’m going to use this. One of the things that always agrivated me when designing websites was not being able to use the fonts I wanted without sacrificing points in SEO. This seems like a much better solution. Keep up the good work.
2:19 pm on November 3rd, 2008
very useful!
javascript always rocks…..
http://weborbus.com
3:48 pm on November 3rd, 2008
Yes, I agree, this technique works great!
5:46 pm on November 3rd, 2008
Wow stunning solution! I’ll definitely try this out! Big plus is that it’s search engine friendly. Thanks for sharing!
2:57 pm on November 11th, 2008
Anybody get this to work (or the new version 0.11) with actual heading tags? Like H1, H2, etc? I can only get it to work with divs and spans. (And this is what I am seeing in examples everywhere…)
3:20 pm on November 11th, 2008
thanks for this tip, will look into putting this on my site. thanks.
6:04 pm on November 11th, 2008
THIS IS THE ONE, folks. Hands down the best. FLIR and SIFR are WAY too complicated for non-code crazy humans, plus FLIR makes a giant cache on your server.
I tried both, and this is a cake-walk, and is easy to tweak.
to: AXIOM: it works on everything for me, p, h1-6, everything.
Only problems with this: the number of fonts available, and difficulty finding them.
dafont.com makes it a lot easier, though: Click on a category (like Cartoon), then go to “More Options” next to the Submit button. In the new fields, check only PUBLIC DOMAIN and FREE (and maybe Shareware?).
Here’s the ones I found so far that work and look good (IMO):
Bellerose, Berliner, Gunplay, Heather, Starcraft
Let’s help each other out and post fonts that we find on here!
7:22 pm on November 11th, 2008
Thanks Geezer, you’ve put down some great tips there.
To get to your latest point: I think these fonts are great too (Able to download from Dafont.com and these are in the public domain):
Geo Sans Light, Clementine Sketch and Rough Typewriter.
I will do a font on this subject soon though!
9:33 pm on November 11th, 2008
Great, thanks, Stefan.
And I forgot: even after you do that search refining on dafont.com, some fonts STILL don’t pass through the conversion. So it can be frustrating, for sure.
12:07 am on November 13th, 2008
Axiom, I stand corrected. You’re right, it doesn’t seam to work on H tags H1 to H6.
p, span and div seam to be all it works on. Still worth it, though.
OK, I did over a clients site using it: http://thecolonelscamp.com/
Check it out and let me know what you think.
I did have one problem on the Covert Combative Arts page: For some reason Firefox didn’t put space between some words when I used spans to change text colors inline (see the source code). So I had to put ” ” (an empty span tag) in between to push the letters apart in a couple places.
Putting in the empty spans didn’t affect IE at all, which is weird….
9:53 pm on November 25th, 2008
Ah, I have found that it does work on H1s, the trick is to add a “font-weight:regular” to your stylesheet. Heading tags are bold by default, and generally, the fonts created by the typeface script are only rendered in a regular weight.
9:59 pm on November 25th, 2008
@axiom - Thanks for the fix! I will include it in the article.