Get computed font-family in JavaScript

Here goes a way to get the computed font-family with JavaScript from the DOM:

let para = document.querySelector('p');
let compStyles = window.getComputedStyle(para);
let computedFontFamily = compStyles.getPropertyValue('font-family') // e.g. "Times New Roman"

Source: https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

Leave a Comment