Supports font-relative units (em, rem), viewport units (vw, vh,
vmin, vmax), and common absolute units (px, cm, mm, Q, in,
pt, and pc). Percentage lengths are not supported because their pixel
value depends on the property and containing element.
Parameters
length: string
CSS length string to convert.
Optionalelement: HTMLElement|null
Element used to resolve em and viewport-relative values.
Returns number
The length expressed in pixels.
Example
import { pixels } from'@pacote/pixels'
// When the root element has `font-size: 16px`: pixels('2rem') // => 32
Converts a CSS length value to pixels.
Supports font-relative units (
em,rem), viewport units (vw,vh,vmin,vmax), and common absolute units (px,cm,mm,Q,in,pt, andpc). Percentage lengths are not supported because their pixel value depends on the property and containing element.