Is there easy way to parse a HTML page to find all the fonts used (or all the font stacks used)?
Or similarly, is there a script that parses a page and returns which CSS rules are included and used or included and are not used?
Examples:
If I parse index.html
, I want to know that 2 font stacks are used: font-family: Georgia, serif
and font-family: Arial, sans-serif
.
Or, if I parse index.html
, I want to know that lines 10, 12, and 15 of style.css
are used.
I imagine somewhere someone has created an app for this? Anyone know of anything?
Add (download) Google chrome extension or Safari extension on your choice of web browser. Go to webpage where you want to find out the font and click on WhatFont extension. Hover over the webpage. You will find a floating box containing font ,you want to find out.
Go to the Web page with the font you like and highlight the first line of text on the page styled with that font. Press "Ctrl-C" to copy the line of text.
ES2015 way of doing it, also supporting ::before
and ::after
pseudo-selectors.
function listFonts () {
let fonts = []
for (let node of document.querySelectorAll('*')) {
if (!node.style) continue
for (let pseudo of ['', ':before', ':after']) {
let fontFamily = getComputedStyle(node, pseudo).fontFamily
fonts = fonts.concat(fontFamily.split(/\n*,\n*/g))
}
}
// Remove duplicate elements from fonts array
// and remove the surrounding quotes around elements
return [...new Set(fonts)]
.map(font => font.replace(/^\s*['"]([^'"]*)['"]\s*$/, '$1').trim())
}
When running this on StackOverflow, will return ["Times", "Arial", "Helvetica Neue", "Helvetica", "sans-serif", "BlinkMacSystemFont", "Consolas", "Menlo", "Monaco", "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", "monospace"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With