Skip to content

toRem()

Converts a length in pixels to a CSS rem string ("<number>rem").

Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet should scale with root font size (accessibility, user zoom). remValue is the assumed 1rem size in px (browser default is typically 16).

Examples:

ts
const width = toRem(24); // '1.5rem' with default 16px root
ts
// Custom root / design system where 1rem === 10px
const gap = toRem(20, 10); // '2rem'

Released under the MIT License.