Skip to content
Allows you to accurately obtain an element’s em value in pixels using JavaScript.
JavaScript
Find file
Latest commit 58c3349 Tyson Matanich Adding links
Failed to load latest commit information.
.gitattributes Adding to GitHub
.gitignore Adding to GitHub
README.md Adding links
getEmPixels.js Adding to GitHub
getEmPixels.min.js Adding to GitHub

README.md

GetEmPixels

Allows you to accurately obtain an element’s em value in pixels using JavaScript. No more blindly dividing by hard-coded values.

Demo: http://www.matanich.com/examples/get-em-pixels/

Article: http://www.matanich.com/2013/06/24/em-values-javascript/

The basics

GetEmPixels is simple to use and has only one function.

// Get the em or rem value of the documentElement
getEmPixels();

// Get the em value of the #footer element
getEmPixels(document.getElementById('footer'));

Size and delivery

Currently, getEmPixels.js compresses to around 481 bytes (~0.47 KB) after minify. To minify, you might try these online tools: [Microsoft Ajax Minifier]:(http://ajaxmin.codeplex.com/), [Uglify]:(http://marijnhaverbeke.nl/uglifyjs), [Yahoo Compressor]:(http://refresh-sf.com/yui/), or Closure Compiler.

Support

GetEmPixels supports a broad range of browsers and devices (there are currently no known unsupported browsers).

Something went wrong with that request. Please try again.