Use CSS Units Converter

Enter your data below to use the CSS Units Converter

📌 Try these examples:
RESULT

Last updated

CSS Units Overview

CSS has two categories of units: absolute (fixed size regardless of context) and relative (size depends on parent, viewport, or font size). Relative units are preferred for responsive design because they scale with the user's settings and viewport size.

CSS Unit Reference

UnitTypeRelative To
pxAbsolute1/96th of an inch (CSS pixel)
ptAbsolute1/72nd of an inch
emRelativeParent element's font-size
remRelativeRoot element's font-size (html)
%RelativeParent element's value
vwRelative1% of viewport width
vhRelative1% of viewport height
vminRelative1% of smaller viewport dimension
chRelativeWidth of "0" character in current font
dvhRelative1% of dynamic viewport height (mobile)

Unit Conversion Formulas

JavaScript
// px to rem (assuming 16px root font size)
const pxToRem = (px, rootFontSize = 16) => px / rootFontSize;

// rem to px
const remToPx = (rem, rootFontSize = 16) => rem * rootFontSize;

// px to em (relative to parent font size)
const pxToEm = (px, parentFontSize) => px / parentFontSize;

// px to vw (relative to viewport width)
const pxToVw = (px, viewportWidth) => (px / viewportWidth) * 100;

// pt to px
const ptToPx = (pt) => pt * (96 / 72);

console.log(pxToRem(24));    // 1.5 (rem)
console.log(remToPx(1.5));   // 24 (px)
console.log(ptToPx(12));     // 16 (px)

Frequently Asked Questions

Simply enter your data, click the process button, and get instant results. All processing happens in your browser for maximum privacy and security.