JavaScript/CSS Font Detector
JavaScript code to Detect available Fonts using JavaScript and CSS. I wrote a JavaScript code which can be used to guess if a particular font is present in a machine. This may be help of desktop-like web application developers when they want to provide different skins or fonts preferences to their users. This may also be help for blog skin designers which can provide different fonts for different users based on the list of fonts on their machine. Designers dont have to rely on the most common fonts like Arial, Verdana or Times New Roman. Since increasing number of users have modern PC with new operating system / applications, they may very well have a wide array of other common fonts in their machine.

This code works on the simple principle that each character appears differently in different fonts. So different fonts will take different width and height for the same string of characters of same font-size.

We try to create a string with a specified font-face. If the font-face is not available, it takes up the font-face of the parent element. We then compare the width of the string with the specified font-face and width of the string with the font-face of the parent element, if they are different, then the font exists, otherwise not.

The string which we will use to generate the widths can be anything. But I guess we use 'm' or 'w' because these two characters take up the maximum width. And we use a trailing 'l' so that the same width fonts-faces can get separated based on the width of l character.

I have tested it on Firefox 2 and IE 6.0.

Update Now works on Opera 9.10. It required to execute the script after its completely loaded. I guess, Opera cannot calculate the offset width untill all the parents are completely loaded.

Please report bugs and suggestions here.
Released under Apache License, Version 2.0.

 

Working Demo
You can test any Font here:

 

Fonts on your computer

This table below shows which fonts are present on your system. (I have listed some of the most common and some uncommon fonts.)

Johan Sundström has presented this data in a more interesting and cool layout here: http://exhibit.ecmanaut.googlepages.com/installed-fonts.html. Thanks Johan.

Font NameWidthHeightDetected?

 

lalit.org  ›  blog | inspiration | lab | synapsys | who? | bio | email