Get a free trial // Grow your CSS skills // Land your dream job

Check if font-family is Honored

Last updated on:
function checkFont(strFamily) {
  var objDiv = document.createElement('div'); = strFamily;
  objDiv.appendChild(document.createTextNode('FONT TEST'));

  if (window.getComputedStyle) {
      return window.getComputedStyle(objDiv, null).getPropertyValue('font-family') === strFamily;

  return objDiv.currentStyle.fontFamily === strFamily;


var iconFontHonored = checkFont('icomoon');

Reference URL


  1. Ryan McKay
    Permalink to comment#

    Neat! Useful, thanks :)

  2. Federico Brigante
    Permalink to comment#

    This is 100% incorrect. The value of window.getComputedStyle(objDiv, null).getPropertyValue('font-family') will always be what you declared.

    Chrome reports all are missing, Firefox reports all available.

  3. Robert
    Permalink to comment#

    If the topic is validating available fonts I’m not getting how this will help. What I need, and what I think most designers need, is a script that will tell me which of the fonts in the font stack appears when the page appears on each browser and OS.

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed