Grow your CSS skills. Land your dream job.

Last updated on:

Check if font-family is Honored

function checkFont(strFamily) {
  var objDiv = document.createElement('div');

  objDiv.style.fontFamily = strFamily;
  objDiv.appendChild(document.createTextNode('FONT TEST'));

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

  return objDiv.currentStyle.fontFamily === strFamily;
}

Usage

var iconFontHonored = checkFont('icomoon');

Reference URL

Comments

  1. Ryan McKay
    Permalink to comment#

    Neat! Useful, thanks :)

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

    Here: http://codepen.io/anon/pen/HIKDq
    Chrome reports all are missing, Firefox reports all available.

Leave a Comment

Current day month ye@r *

*May or may not contain any actual "CSS" or "Tricks".