// Convert rem value to pixels constremExample=convertCssUnit('2.5rem');// Convert time unit (seconds) to milliseconds constspeedExample=convertCssUnit('2s');// Convert angle unit (grad) to degrees constemExample=convertCssUnit('200grad');// Convert vw value to pixels constvwExample=convertCssUnit('80vw');// Convert the css variable to pixels constvarExample=convertCssUnit(getComputedStyle(document.body).getPropertyValue('--container-width'));// Convert `em` value relative to page element constemExample=convertCssUnit('2em',document.getElementById('#my-element'));
Supported units
Any format with preceding plus (+) or minus (-) symbol is valid, along with any of the following units: px, cm, mm, q, in, pc, pt, rem, em, vw, vh, s, ms, deg, rad, grad, turn