Search code examples
javascriptcssbrowserfonts

list every font a user's browser can display


Is there a way in javascript to obtain the names of all fonts (or font-families) that the browser can show? (I want to give the user a dropdown with a list of all available fonts, and allow the user to choose a font.) I'd prefer not to have to hardcode this list ahead of time or send it down from the server. (Intuitively, it seems like the browser should know what fonts it has and this should be exposed to javascript somehow.)


Solution

  • The JavaScript version is a bit flaky. It gets fonts by iterating through known fonts and testing.

    The most accurate way (albeit having to use a proprietary plugin) is to use Flash. Here you can get the list of fonts without having to test for them individually using dimensions.

    You are going have to decide whether to have an exact list at the expense of not working on some devices (iDevices, browsers without Flash plugin, etc), or a partial list with better support via JavaScript only.