CSS Unit Converter: Convert px, rem, em, pt, and Viewport Units, or Rewrite a Whole Stylesheet

Key Takeaways
- CSS length units fall into three groups: absolute units such as px, pt, pc, in, cm, and mm; font-relative units such as rem, em, and percent; and viewport units such as vw, vh, vmin, and vmax.
- rem is tied to the root font size, usually on the HTML element, so type and spacing scale when the user or the stylesheet changes that root size. em is tied to the parent (or to the element itself, depending on the property), and nested em font sizes multiply through the tree.
- px is the right choice for 1px borders and hairlines. It is a poor default for body type, because it does not track the root font size the way rem does, which matters for WCAG text resizing.
- On mobile screens, 100vh is defined against the large viewport, so a full-height section can sit underneath the browser chrome. Prefer svh or dvh when the visible viewport matters. This converter handles vw, vh, vmin, and vmax on the value tab; it does not convert svh, lvh, or dvh.
- Use the value tab to convert one length into all 13 units, with your root font size, parent font size, and a screen size. Use the stylesheet tab to rewrite px, rem, em, or pt values in pasted CSS or a .css file, entirely in your browser.
Convert any CSS length between px, rem, em, pt, pc, in, cm, mm, %, vw, vh, vmin, and vmax, using your own root font size and a standard screen size. Or paste a stylesheet and rewrite its pixel values to rem.
CSS Unit Converter v1.0.0Last Update: Nov 20, 2026
Type a size in any unit to see it in all the others, or paste a stylesheet to rewrite its pixel values. Set the root font size, the parent font size and the screen below, because rem, em, % and the viewport units all depend on them.
- Pixels (px)
—Copy- Root em (rem)
—Copy- Em (em)
—Copy- Points (pt)
—Copy- Picas (pc)
—Copy- Inches (in)
—Copy- Centimeters (cm)
—Copy- Millimeters (mm)
—Copy- Percent of parent font size (%)
—Copy- Viewport width (vw)
—Copy- Viewport height (vh)
—Copy- Smaller viewport side (vmin)
—Copy- Larger viewport side (vmax)
—Copy
Quick reference table
Rows use the root and parent font sizes above. Pixels, points and picas are fixed (1in = 96px = 72pt = 6pc); rem, em, % and the viewport units change with your settings.
Preview of changes
Absolute units use the CSS reference pixel: 1in = 96px = 72pt = 6pc = 2.54cm. Percent here means percent of the parent font size, which is how it behaves on font-size. For lengths such as width, % is relative to a container instead.
CSS Length Units: Absolute, Font-Relative, and Viewport
Every length in a CSS rule is a number plus a unit, with no space between them. The unit decides what that number is relative to: a fixed reference, the font size of the page or a parent, a percentage, or the viewport. The CSS values and units guide on MDN Web Docs is a useful map of the full set, including units this converter does not cover, such as ch, cap, and container queries.
Absolute Units: px, pt, pc, in, cm, and mm
The absolute units are fixed in relation to each other. On screens they are almost always anchored to the CSS reference pixel, not to a ruler you can hold up to the display. That is why 1in in a stylesheet is not reliably one physical inch on a phone or a retina laptop.
For screen media, CSS anchors these units to the reference pixel, not a physical ruler. One inch equals 96 pixels, one point is 1/72 of an inch, and one pica is 12 points, so 12pt equals 16px. The pixel is the canonical absolute unit.
Tab Atkins and Elika J. Etemad, CSS Values and Units Module Level 4, W3C Working Draft, 12 March 2024
px is the unit you will see most often in older stylesheets and in design-tool exports. It is predictable: 16px is 16px, regardless of the parent font size. That predictability is also the drawback for typography. A heading locked to 32px will not grow or shrink when the user changes the root font size, and a tightly fixed layout can break when text is resized.
Points (pt) and picas (pc) come from print typography. They are still the natural units in a print stylesheet, where many layout tools and print specs are written in points. On screen, they simply map back to pixels through the same reference (12pt equals 16px). Inches, centimeters, and millimeters follow the same mapping, so they are useful when you already think in physical units, and misleading if you expect a phone to honor a tape measure. CSS also defines a quarter-millimeter unit, Q, which this converter does not include.
Root-Relative Units: rem
rem is a font-relative length equal to the computed font size of the root element, usually the HTML element. If the user or the stylesheet changes that root size, every rem value on the page scales with it.
Browsers start with a 16px root font size unless the user or the page changes it. At that default, 1rem equals 16px, 1.5rem equals 24px, and 0.875rem equals 14px. Some stylesheets set the root to 62.5% so that 1rem equals 10px and the mental math is easier. If you are converting a site that does that, set the converter’s root font size to 10px, not 16px.
The accessibility case for rem is the main reason to prefer it for type and for spacing that should track type. If body copy, headings, padding, and gaps are all in rem, a user who enlarges the default font size, or a page that raises the root size, gets a layout that grows together instead of a cramped box around stubborn pixel type.
WCAG 2.2 Success Criterion 1.4.4, Resize Text, requires that text can be resized without assistive technology up to 200 percent without loss of content or functionality, except for captions and images of text.
W3C Web Accessibility Initiative, Understanding Success Criterion 1.4.4: Resize Text (WCAG 2.2), updated 6 September 2026
That does not mean every length on a page must be rem. It does mean typography should be able to grow. As the CSS length reference on MDN Web Docs notes, em and rem are often used to create scalable layouts that keep their vertical rhythm when the user changes the font size.
Parent-Relative Units: em and Percent
em is relative to a font size in the element’s own context. When you use it on font-size, it is the parent’s font size. When you use it on padding, margin, width, or line-height, it is the element’s own computed font size.
That second behavior is useful: a button with padding of 0.75em and a font size of 1em will stay in proportion if you later change only the button’s font size. The first behavior is where teams get hurt. If an article is 1.25em, a heading inside it is 1.5em, and a caption inside the heading is 0.8em, those values multiply. Starting from a 16px root, the article is 20px, the heading is 30px, and the “smaller” caption is 24px. The same numbers in rem stay tied to the root: 20px, 24px, and 12.8px.
Percent is even more context-dependent. On font-size, 100% equals the parent font size, so 100% and 1em are equivalent there, and that is how this converter treats %. On width, height, padding, or margin, a percentage is usually a share of the containing block, not of a font size. If you type 50% into the value tab, you are converting 50 percent of the parent font size you set, which is the right math for type and the wrong math for a column that should be half as wide as its container.
Viewport Units: vw, vh, vmin, and vmax
Viewport units are percentages of the viewport, the area of the window or device screen that the page can use. 1vw is 1 percent of the viewport width, 1vh is 1 percent of the viewport height, vmin is 1 percent of the smaller side, and vmax is 1 percent of the larger side. They are excellent for fluid type, full-bleed backgrounds, and decorations that should track the screen. They are risky for body copy, because 4vw on a 320px-wide phone is 12.8px and on a 1920px desktop is 76.8px.
The mobile vh problem is a specification issue, not a browser bug. When a mobile browser shows its address bar or toolbar, the visible area shrinks, but the default vh unit does not.
The default viewport units, including vh, are defined against the large viewport size: the viewport with dynamic browser interface chrome retracted. Content sized to 100vh can sit underneath the address bar or toolbar when those interfaces are expanded. The small viewport units (svh) assume those interfaces are expanded, and the dynamic viewport units (dvh) update as they appear and disappear.
Tab Atkins and Elika J. Etemad, CSS Values and Units Module Level 4, W3C Working Draft, 12 March 2024
For a full-height hero, a sheet, or a mobile panel, prefer 100dvh or 100svh over 100vh. The value tab of this converter still uses the classic vw, vh, vmin, and vmax units, because those are the ones most existing stylesheets already contain. It does not convert svh, lvh, or dvh. If you already know the visible height you care about, you can enter that height as the screen size and read the matching vh value, then swap in dvh or svh in your stylesheet by hand.
When to Use Each Unit
There is no single correct unit. The better question is what should happen when the root font size, the parent, or the viewport changes. Use rem when the answer is “scale with the page.” Use em when the answer is “scale with this component.” Use px when the answer is “stay exactly this thin.” Use a viewport unit when the answer is “track the screen,” and reach for svh or dvh when the visible mobile viewport is what you actually mean.

| Job | Prefer | Why | Watch Out For |
|---|---|---|---|
| Type, headings, and spacing that should track type | rem | Scales with the root and with user font settings | A site that sets the root to 62.5% so 1rem equals 10px |
| Padding, margin, or width inside a component that should track its own font size | em | The control stays in proportion if you change only that font size | Nested em font sizes, which compound through the tree |
| 1px borders, outlines, and hairline dividers | 1px | Stays a thin, predictable line | Converting those hairlines to rem, which can disappear or thicken when the root changes |
| Print style sheets | pt, in, cm, or mm | Print tools and specs are still written in points and physical units | Using them for on-screen type, where they map to the reference pixel, not a desk ruler |
| Full-height heroes, sheets, or mobile panels | dvh or svh | Matches the visible viewport more closely than the default vh unit | 100vh on mobile, which can overflow when the browser chrome is showing |
| A column or image that should be a share of its container | % of the containing block, or flex and grid | Width percentages are relative to the container, not to a font size | Typing that same % into this converter, which treats % as a share of the parent font size |
| Fluid decorative type or shapes that should track the screen | vw, vmin, or a clamped combination | The size changes smoothly as the viewport changes | Body copy in raw vw, which becomes too small on phones and too large on desktops |
How to Use the CSS Unit Converter
Set the context first, then type a value. Root font size defaults to 16px, which is the browser default. Parent font size starts at the same number and follows the root until you edit it; change it when you are converting em or % inside a component whose parent is not the root. Screen size is used only for vw, vh, vmin, and vmax. It defaults to a 1920 by 1080 desktop, and the preset list covers common phone, tablet, and laptop CSS viewports from 360 by 800 up to 2560 by 1440. You can also choose Custom size and enter a width and height. Those sizes are CSS pixels (the viewport a page sees), which is smaller than the physical pixel count on a high-density screen.
- On the Convert a Value tab, enter an amount and choose the unit you are starting from. Negative values are allowed, which is useful for margins and offsets.
- Read the result list. Every supported unit updates as you type, and each row has a Copy button.
- Open the quick reference table when you want a compact px, rem, em, pt, and % chart at the root and parent sizes you set. The rows cover common type and spacing sizes from 8px through 96px.
The summary line restates the value in px, rem, em, and pt and reminds you which root, parent, and screen you are using. If a field is empty or not a number, the converter asks you to fix that field before it will show results.
How to Rewrite a Whole Stylesheet
The Convert a Stylesheet tab rewrites every matching length in a block of CSS, or in a .css file you choose or drop onto the page. The file is read in your browser. Nothing is uploaded or stored, and files larger than 2 MB are rejected so you can paste the section you actually want to convert. You can convert from and to px, rem, em, or pt. rem is the default target, and it is the safer choice for a whole file, because every rem value shares one root. em still depends on each element’s parent, so a whole-file em conversion uses the single parent font size you set at the top of the tool.
A few options control what gets touched:
- Keep 1px borders and hairlines as px is on by default when you are converting from px. Values of 1px or less are left alone, so a 1px border does not become 0.0625rem and then disappear or thicken later.
- Also convert media query sizes is off by default. Turn it on only if you want @media and @container lengths converted too. In media and container queries, rem and em mean the browser’s initial font size, which is 16px, not the root size of your page. The converter honors that and uses a 16px base for those queries even if you have set a different root above.
- Skip these properties accepts a comma-separated list of prefixes. Entering border also skips border-width and border-left. This is a good place to park box-shadow or letter-spacing if you want those left in px.
- Decimal places defaults to 4 and can be set from 2 through 6.
The rewriter leaves comments, strings, url() values, selectors, zeroes, and custom property names alone. A token such as –space-16px is not treated as a length, because the number is part of an identifier. Click Convert Stylesheet to see a summary of how many values changed, the rewritten CSS, and a preview of each change (the preview lists up to 200 rows). From there you can copy the result or download it as a .css file. Load Sample inserts a short example if you want to try the options first, and Reset clears the tab.
Two limits are worth planning for. Because em and % depend on each element’s own context, a single parent size cannot be perfect across a large file; review nested components after you convert, or convert those blocks separately with a different parent size. Viewport units, percentages used as container shares, and the physical units (pc, in, cm, mm) are not rewritten on this tab. Convert those one value at a time on the value tab, or leave them as they are.
CSS Unit Conversion Reference
These equivalences follow the CSS reference pixel in the Values and Units specification cited above. They do not change with the root font size or the viewport. Use them when you are moving between pixels, points, and the physical units.
| Unit | Name | Equals |
|---|---|---|
| 1px | Pixel | 1/96 of 1in |
| 1pt | Point | 1/72 of 1in, or 1.333px |
| 1pc | Pica | 12pt, or 16px |
| 1in | Inch | 2.54cm, or 96px |
| 1cm | Centimeter | 96px / 2.54, or about 37.795px |
| 1mm | Millimeter | 1/10 of 1cm, or about 3.779px |
At a 16px root and a 16px parent, the following type and spacing sizes are the ones you will convert most often. If your root is 10px or 18px, use the converter’s quick reference table instead, because rem, em, and % will all change.
| px | rem (16px root) | em (16px parent) | pt | % of parent font |
|---|---|---|---|---|
| 8px | 0.5rem | 0.5em | 6pt | 50% |
| 10px | 0.625rem | 0.625em | 7.5pt | 62.5% |
| 12px | 0.75rem | 0.75em | 9pt | 75% |
| 14px | 0.875rem | 0.875em | 10.5pt | 87.5% |
| 16px | 1rem | 1em | 12pt | 100% |
| 18px | 1.125rem | 1.125em | 13.5pt | 112.5% |
| 20px | 1.25rem | 1.25em | 15pt | 125% |
| 24px | 1.5rem | 1.5em | 18pt | 150% |
| 32px | 2rem | 2em | 24pt | 200% |
| 48px | 3rem | 3em | 36pt | 300% |
| 64px | 4rem | 4em | 48pt | 400% |
| 96px | 6rem | 6em | 72pt | 600% |
Viewport conversions always need a width and a height. At a 1920 by 1080 desktop, 1vw equals 19.2px and 1vh equals 10.8px. At a 390 by 844 phone viewport, 1vw equals 3.9px and 1vh equals 8.44px. Pick the matching preset in the converter when you want the rest of the units filled in for a specific value.
Frequently Asked Questions
What Is the Difference Between px, rem, and em?
px is an absolute unit anchored to the CSS reference pixel. rem is relative to the root font size, so it scales when that root size changes. em is relative to a parent or to the element itself, so nested em font sizes multiply. For typography and page-level spacing, rem is usually the safer choice.
How Many Pixels Are in 1rem?
One rem equals the computed font size of the root element. Browsers default to 16px, so 1rem is 16px until the user or the stylesheet changes that root. If the page sets html to 62.5%, 1rem is 10px. Set the converter’s root font size to match the site you are editing.
Should I Convert a Whole Stylesheet From px to rem?
Yes for typography, spacing, and most layout lengths that should scale with the root font size. Leave 1px borders and hairlines in px, which is why that option is on by default. Review nested components if you also convert em, and think twice before converting media queries, because rem and em inside a query use the browser’s 16px initial font size, not your page root.
Why Don’t My Inches and Centimeters Match a Physical Ruler?
On screens, CSS anchors the physical units to the reference pixel: 1in is defined as 96px. That keeps units consistent across devices, but it means 1in in a stylesheet will not reliably measure one inch on a phone or a high-density laptop. Use pt, in, cm, or mm in print stylesheets, where the output can be tied to a physical measurement.
What Is Wrong With 100vh on Mobile?
The default vh unit uses the large viewport, which assumes the browser chrome is hidden. A 100vh section can therefore be taller than the visible area when the address bar or toolbar is showing. Use 100svh or 100dvh when you need the section to fit the visible viewport. The converter’s value tab still works in vw, vh, vmin, and vmax; it does not output svh, lvh, or dvh.
Does the Stylesheet Converter Change Media Queries?
Only if you turn on Also convert media query sizes. When that option is on, the tool also converts lengths in @media and @container preludes, using a 16px base, which is how rem and em are defined in those queries. Leave the option off if your breakpoints should stay in px.
Is My CSS Uploaded to a Server?
No. Pasted CSS and .css files are read and converted in your browser. Nothing is uploaded or stored. The file picker will not accept a file larger than 2 MB; paste the section you need instead.
Why Did em Values Look Wrong After a Stylesheet Conversion?
The stylesheet tab has one parent font size for the whole file, but em depends on each element’s own parent. A heading inside a 1.25em article is not using the root as its parent. Convert those nested blocks separately with a matching parent size, or prefer rem for page-level type so the values do not compound.



