CSS Unit Converter

Enter a Value to Convert Between CSS Units

px

Result:

Converted value will appear here
Support Us Add as a preferred source on Google (opens in new tab)

About the CSS Unit Converter

Convert between px, rem, em, %, vw, vh, pt, pc, in, cm, and mm and get instant, accurate results with a single input. This free CSS Unit Converter is ideal for web developers and designers building responsive, pixel-perfect layouts.

Contents [hideshow]

Why CSS Unit Conversions Matter

Anything well-built mostly runs on consistency. In music, it's beats. In programming, it's logic. And in web design, it's CSS units. They bring consistency and control to size, spacing, and flow. Without them, a layout isn't flexible, it's just code held together with school glue.

When you write a stylesheet, every pixel you enter has a direct impact on the scale, accessibility, and responsiveness of the web page. The wrong unit can make a layout overflow on a small screen, ignore the user's font size setting, or break in print. The right one lets the same design work on any screen and on paper.

So, how do you ensure you always choose the right CSS Unit?

Start by asking yourself: what should this scale with? For example, is it text that respects user preference, or the elements tied to a parent container, or layout tied to viewport size, or are you dealing with fixed, precise elements like borders, icons, etc. Theoretically, there is no single 'correct' unit; it all depends on what you want it to respond to.

Most mistakes come from using a unit that responds to the wrong reference. Furthermore, because CSS offers so many distinct length units, converting between them manually could lead to errors and a tedious workflow. That is exactly why a reliable CSS Unit Converter like the Syntax Toolbox CSS Unit Converter that supports all 11 of the most commonly used CSS units - px, rem, em, %, vw, vh, pt, pc, in, cm, and mm - with configurable base font sizes, PPI/DPI settings, and viewport dimensions is worth keeping open while you work.

Understanding CSS Units at a Glance

Relative CSS Units

Unit Sign used Description
Root EmremRelative to the root element's (html) font size.
EmemRelative to the parent's font size on font-size, and to the element's own font size on other properties.
Percentage%Relative to the parent element's size on most properties.
Viewport Widthvw1% of the browser viewport's width.
Viewport Heightvh1% of the browser viewport's height.

Absolute CSS Units

Unit Sign used Description
PixelspxLogical CSS pixel. 1px = 1/96 of an inch.
Pointspt1pt = 1/72 of an inch.
Picaspc1pc = 12 points (1/6 of an inch).
Inchesin1in = 96px = 72pt
CentimeterscmMetric unit. 1cm ≈ 37.8px; 100cm = 1 meter.
MillimetersmmMetric unit. 1mm ≈ 3.78px; 1000mm = 1 meter.

How to Use the Syntax Toolbox CSS Unit Converter

Syntax Toolbox CSS Unit Converter supports all 11 units listed above. Want to use our Converter? Here's how:

  • Step 1: Select a CSS Unit to convert from (Relative or Absolute Unit).
  • Step 2: Select another Unit (Relative or Absolute).
  • Step 3: Adjust the reference value, such as Base Font/REM size, if the conversion needs one.
  • Step 4: Enter a value to convert and check results in real-time.

Results appear as you type, with no extra buttons to press.

To simplify the process, the Syntax Toolbox CSS Unit Converter comes with default reference values, such as Base Font/REM Size. Here's the full list:

Sr. No. Conversions between Default Size
1Pixels to remBase Font/REM Size defaults to 16
2Pixels to emParent Font/EM Size defaults to 16
3Pixels to PercentageParent Element Size defaults to 1000
4Pixels to Viewport WidthViewport Width defaults to the user's browser window width
5Pixels to Viewport HeightViewport Height defaults to the user's browser window height
6Pixels to (pt, pc, in, cm, mm)PPI/DPI (Resolution) field defaults to 96

Common CSS Unit Conversions and Formulas

Below are the exact formulas the Syntax Toolbox CSS Unit Converter uses. Unless stated otherwise, the examples assume the browser default of 16px for the root font size, 16px for the parent font size, and a 1920×1080px viewport. In the tool, the viewport fields start with your own browser window size, and you can change any of these values.

px to rem converter

rem = px ÷ base font size

Example: 24px ÷ 16 = 1.5rem

rem to px converter

px = rem × base font size

Example: 1.5rem × 16 = 24px

px to em converter

em = px ÷ parent font size

Example: 20px ÷ 16 = 1.25em

em to px converter

px = em × parent font size

Example: 1.25em × 16 = 20px

px to % converter

% = (px ÷ parent element size) × 100

Example: 480px ÷ 1200px × 100 = 40%

px to vw converter

vw = (px ÷ viewport width) × 100

Example: 960px ÷ 1920px × 100 = 50vw

px to vh converter

vh = (px ÷ viewport height) × 100

Example: 540px ÷ 1080px × 100 = 50vh

px to pt converter

pt = px × (72 ÷ 96) = px × 0.75

Example: 16px × 0.75 = 12pt

pt to px converter

px = pt × (96 ÷ 72) ≈ pt × 1.333

Example: 12pt × (96 ÷ 72) = 16px

px to in converter

in = px ÷ 96

Example: 192px ÷ 96 = 2in

px to cm converter

cm = px ÷ 37.795

Example: 96px ÷ 37.795 ≈ 2.54cm

px to mm converter

mm = px ÷ 3.7795

Example: 38px ÷ 3.7795 ≈ 10.05mm

Reverse and Cross-Unit Formulas

These formulas cover the reverse conversions and conversions between relative units. When you convert between em and rem, pixels are always the middle step, which is why both font sizes show up in the formula.

Conversion Formula Example
% to pxpx = % × parent size ÷ 10040% of 1200px = 480px
vw to pxpx = vw × viewport width ÷ 10010vw at 390px = 39px
vh to pxpx = vh × viewport height ÷ 10050vh at 1080px = 540px
in to pxpx = in × 962in = 192px
cm to pxpx = cm × 96 ÷ 2.545.08cm = 192px
mm to pxpx = mm × 96 ÷ 25.410mm ≈ 37.8px
pc to pxpx = pc × 163pc = 48px
px to pcpc = px ÷ 1680px = 5pc
em to remrem = em × parent font size ÷ root font size1.5em (20px parent, 16px root) = 1.875rem
rem to emem = rem × root font size ÷ parent font size2rem (16px root, 20px parent) = 1.6em
rem to vwvw = rem × root font size ÷ viewport width × 1002rem at 1440px ≈ 2.2222vw

px to rem, em, and pt Conversion Chart (16px Base)

Here are the sizes you'll reach for most often, already converted. The rem column uses the default 16px root, and the em column assumes a 16px font size on whatever the em refers to. If your project uses the 62.5% root trick, read the last column instead.

px rem (16px root) em (16px) pt rem (62.5% root)
4px0.25rem0.25em3pt0.4rem
8px0.5rem0.5em6pt0.8rem
10px0.625rem0.625em7.5pt1rem
12px0.75rem0.75em9pt1.2rem
14px0.875rem0.875em10.5pt1.4rem
16px1rem1em12pt1.6rem
18px1.125rem1.125em13.5pt1.8rem
20px1.25rem1.25em15pt2rem
24px1.5rem1.5em18pt2.4rem
28px1.75rem1.75em21pt2.8rem
32px2rem2em24pt3.2rem
36px2.25rem2.25em27pt3.6rem
40px2.5rem2.5em30pt4rem
48px3rem3em36pt4.8rem
56px3.5rem3.5em42pt5.6rem
64px4rem4em48pt6.4rem
72px4.5rem4.5em54pt7.2rem
80px5rem5em60pt8rem
96px6rem6em72pt9.6rem
100px6.25rem6.25em75pt10rem

px to vw Chart by Viewport Width

A vw value means nothing without a screen width next to it. The same 24px is 6.4vw on a 375px phone but only 1.25vw on a 1920px monitor, so match the column to the width of your design file. For reference, 1vw is 3.75px, 14.4px, and 19.2px at these three widths.

px 375px wide 1440px wide 1920px wide
8px2.1333vw0.5556vw0.4167vw
16px4.2667vw1.1111vw0.8333vw
24px6.4vw1.6667vw1.25vw
32px8.5333vw2.2222vw1.6667vw
48px12.8vw3.3333vw2.5vw
64px17.0667vw4.4444vw3.3333vw
96px25.6vw6.6667vw5vw
100px26.6667vw6.9444vw5.2083vw

CSS Units in Real-World Web Layouts

Now that you know the basics of how CSS units work, here is how each one behaves in real-world layouts. Each CSS unit has its own scaling logic, strengths, and edge cases, and knowing them helps you build layouts that stay responsive.

Relative CSS Units Explained

Relative units are what make a web design responsive and accessible, because they scale with user preferences and viewport dimensions. This is what makes it possible for a single stylesheet to look consistent across a 320px-wide phone as well as a 4K monitor.

Let's have a look at all the Relative Units supported by the Syntax Toolbox CSS Unit Converter:

rem - Root EM

1rem equals the font size declared on the html element. By default, browsers set this to 16px (unless changed), so the standard conversion becomes: 1rem = 16px

Because rem is tied to the root font size, it respects user browser settings and improves accessibility. Adjusting the root value allows you to scale the entire interface proportionally.

CSS
html {
    font-size: 100%; /* 16px by default */
}

.title {
    font-size: 2rem; /* 2 x 16px = 32px */
}

.card {
    padding: 1.5rem; /* 1.5 x 16px = 24px */
}
  • The html element's font-size is 100%, which is 16px by default, so 1rem equals 16px everywhere in the document.
  • Therefore, the title's font-size is 32px (2 × 16px) and the card's padding is 24px (1.5 × 16px), no matter how deeply either element is nested.

For mixed contexts where element-specific scaling is required, use em instead.

em - Element Em

The em unit is relative to a font size, and which one depends on the property. On font-size, 1em is the parent element's computed font size. On every other property, such as padding or margin, it is the element's own font size. If no font size is explicitly set, the element inherits the value from its parent, ultimately tracing back to the root.

Unlike rem, em is context-based and can compound in nested structures, since each element calculates its font-size from its immediate parent rather than the root.

CSS
.notice {
    font-size: 20px;
    padding: 0.75em 1em; /* 15px 20px - tied to this block's own text */
}

.notice__tag {
    font-size: 0.8em; /* 0.8 x 20px = 16px */
}

.notice__tag sup {
    font-size: 0.8em; /* 0.8 x 16px = 12.8px, not 16px */
}

Notice what happens on the last rule. The tag already shrank to 16px, so its own child starts measuring from 16px instead of the original 20px: 0.8 × 16px = 12.8px

This cascading behavior means values can grow or shrink quickly across deeply nested components. Because of this, em must be used carefully in nested layouts where unintended scaling can occur due to repeated multiplication.

For cases where sizing needs to be relative to the parent element's dimensions rather than font size, use the % unit.

% - Percentage

On most layout properties, the % unit is relative to the size of the parent element. Unlike em and rem, it is not based on a font size there, and it can apply to width, height, padding, margins, and positioning.

The behavior of % depends on the property it is applied to, making it flexible for layout control but context-dependent in calculation.

CSS
.shell {
    display: flex;
    width: 960px;
}

.shell__aside {
    width: 25%; /* 25% of 960px = 240px */
    padding: 2%; /* 19.2px on every side - resolved from width */
    box-sizing: border-box; /* padding stays inside the 240px */
}

.shell__main {
    width: 75%; /* 75% of 960px = 720px */
}
  • Widths resolve against the parent's width, so the two columns add up to the 960px shell.
  • Percentage padding and margin always resolve against the parent's width, even for the top and bottom sides. That is what makes the classic padding-top aspect-ratio trick work.
  • On font-size, a percentage behaves exactly like em: 150% is 1.5 times the parent's font size.

% behaves similarly to em for font-size but is generally clearer for layout dimensions.

For viewport-based sizing that responds to the browser window instead of the parent element, use vw.

vw - Viewport Width

1vw equals 1% of the browser's current viewport width. For example, an element set to width: 50vw will always occupy 50% of the viewport's horizontal space, regardless of screen size.

Unlike %, which is relative to the parent element, vw is relative to the viewport itself, making it useful for true screen-based scaling. For example, a phone has a smaller vw than an HD TV.

CSS
.banner {
    /* break a section out of a centered, max-width page */
    width: 100vw;
    margin-inline: calc(50% - 50vw);
}

.banner__inner {
    width: 50vw; /* 1440px viewport = 720px */
    padding-inline: 4vw; /* gutters grow with the screen */
}

One thing to keep in mind: vw counts the scrollbar width on desktop browsers, so an element set to 100vw can overflow a page that already has a vertical scrollbar. Use 100% when you only need the container's width.

vw allows for width-based scaling. For height-based viewport scaling, use vh.

vh - Viewport Height

1vh equals 1% of the browser's current viewport height. For example, an element set to height: 25vh will always occupy 25% of the viewport's vertical space, regardless of screen size.

CSS
.slide {
    min-height: 100vh; /* one screen per slide */
    scroll-snap-align: start;
}

.slide__figure {
    height: 60vh; /* 1080px viewport = 648px */
}

.sticky-nav {
    position: sticky;
    top: 0;
    max-height: 25vh; /* never eats more than a quarter of the screen */
    overflow-y: auto;
}

On mobile browsers, 100vh can behave inconsistently due to dynamic browser UI (address bar, toolbars). In such cases, newer units like svh, dvh, and lvh provide more precise control over viewport behavior. Our CSS Unit Converter focuses on the classic units supported across all browsers.

Absolute CSS Units Explained

Absolute units represent fixed physical (or logical) sizes. They do not respond to user preferences or viewport changes, making them predictable but less suitable for responsive interfaces. Absolute units shine in print stylesheets and designs where exact physical dimensions are required.

Let's explore the Absolute Units supported by the Syntax Toolbox CSS Unit Converter:

px - Pixels

CSS pixels are device-independent (logical) units, not physical screen pixels. One CSS pixel is defined as 1/96th of a logical inch.

On high-DPI (Retina) displays, the OS scales content so that multiple physical pixels are used to render one CSS pixel. As a result, px remains visually consistent regardless of the device's actual pixel density.

Although pixels are considered an absolute unit in CSS, they represent logical measurements instead of fixed physical dimensions. That predictability is why px still earns its place in fine visual details such as borders, dividers, and shadows, the parts of an interface that should not grow just because the text around them did.

CSS
.card {
    border: 1px solid #d0d7de; /* stays 1px whatever the font size */
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.card__divider {
    height: 1px; /* a relative unit here could round down to 0 and vanish */
    background: #d0d7de;
}

pt - Points

Points are a typographic unit traditionally used in print design where one point equals 1/72 of an inch.

In web development, pt is rarely used for screen layouts, but it becomes relevant when matching typography to print specifications or design files exported from applications such as Adobe InDesign or Illustrator.

CSS
@media print {
    body {
        font-size: 11pt; /* 11 x 1.333 = 14.67px */
        line-height: 1.4;
    }

    h1 {
        font-size: 24pt; /* matches the 24pt heading in the print spec */
    }
}

pc - Picas

Picas are a typographic unit popularly used in professional publishing and grid-based print layouts. One pica equals 12 points, or 1/6 of an inch.

The difference between pt and pc is simple:

  • pt = micro (type sizing).
  • pc = macro (layout structure).
CSS
@media print {
    .invoice {
        width: 45pc; /* 45 x 12pt = 540pt = 7.5in text column */
        margin: 0 auto;
    }

    .invoice__section + .invoice__section {
        margin-top: 2pc; /* 24pt of vertical rhythm between blocks */
    }
}

in - Inches

Inches are a physical measurement unit commonly used in print and hardware specifications. One inch is defined as 96px in web contexts.

Unlike typographic units such as pt and pc, inches represent real-world physical length, which makes them useful for print layout systems, packaging dimensions, and print-preview accuracy.

On screen, an inch is always 96px, so its physical size varies from one display to another and rarely matches a ruler.

CSS
@page {
    size: 8.5in 11in; /* US Letter */
    margin: 0.75in;
}

.certificate {
    width: 7in; /* 8.5in page minus both 0.75in margins */
    padding: 0.5in;
    box-sizing: border-box; /* padding stays inside the 7in */
}

cm - Centimeters

Centimeters are a metric physical unit used to represent real-world length. In CSS, 1cm is defined as 96px ÷ 2.54, or approximately 37.795px.

Like inches and points, centimeters are primarily a print unit. They are useful when your design references metric measurements or when generating PDFs and print layouts through the browser.

CSS
@page {
    size: 21cm 29.7cm; /* A4 */
    margin: 1.5cm;
}

.label-sheet__item {
    width: 6.4cm;
    height: 3.4cm; /* standard address label */
    padding: 0.3cm;
    box-sizing: border-box; /* keeps the label 6.4cm x 3.4cm */
}

mm - Millimeters

Millimeters are another physical metric unit, where 1mm is defined as approximately 3.78px in CSS.

Compared to cm, millimeters are used for finer detail and tighter measurement control in print-based layouts, especially when precision matters in spacing, margins, or small-scale design elements.

In web development, mm is the finer of the two metric units covered here, and it is useful for print layouts and PDFs generated in the browser.

CSS
@page {
    size: 210mm 297mm; /* the same A4 sheet, in millimeters */
    margin: 12mm;
}

.business-card {
    width: 85mm;
    height: 55mm;
    border: 0.2mm dashed #999; /* fine cut guide */
}

Relative vs. Absolute CSS Units: Key Differences

Key Difference Relative Units Absolute Units
ResponsivenessHighly responsive; values adapt based on surrounding context like parent, root, or viewport.Not responsive; values are fixed and do not adjust based on screen size or resolution.
DependencyDependent on relative factors like font size, container, or viewport dimensions.Independent of parent elements or viewport for calculation.
ScalabilityAutomatically adjusts to different screen sizes.Less adaptable across different screen sizes.
FlexibilitySize may vary depending on parent or viewport, allowing for more fluid and dynamic layouts.Provides consistent and exact sizing regardless of environment.
AccessibilityAdapt to user settings such as base font size, improving accessibility.Do not respond to the user's browser font size setting, hindering accessibility.
ComputationNeed a reference value, such as a font size or viewport width, to resolve to pixels.Resolve to a fixed number of CSS pixels without a reference value.

Choosing the Right CSS Unit for Your Layout

Instead of thinking in terms of individual units, think in terms of what the value should respond to: the root, the parent, or the viewport. Once you know that, the unit is easy to pick.

Font sizes

  • Use rem for font sizes. It scales with the user's browser font preference and provides consistent sizing across the entire document.
  • Avoid px for font sizes, as it ignores the user's default font size setting (browser zoom still works).

Padding and Margin

  • Use rem for global spacing to keep it proportional to typography.
  • Use em when you want spacing to scale relative to the component's own font size. Ideal for buttons and badges.
  • Avoid px for layout spacing unless you need strict pixel precision.

Layout Widths and Columns

  • Use % for fluid columns inside flex or grid containers.
  • Use vw for full-viewport-width elements.

Heights

  • Use vh for full-screen sections (e.g., hero banners, landing screens).
  • Use auto for content-driven height (recommended default).
  • Use fixed units (rem or px) only when height must be strictly controlled (e.g., toolbars, inputs, buttons).

Borders and Box Shadows

  • Use px for borders and shadows. These are fine visual elements that should remain consistent regardless of text or layout scaling.
  • Avoid relative units here, as they can make UI elements appear inconsistent across components.

Media Query Breakpoints

  • Prefer em or rem over px. These units respond to user font-size settings, making layouts more accessible and adaptable.
  • Convert breakpoints with 16 as the base, even if your stylesheet uses the 62.5% trick. Inside a media query, em and rem ignore the root size you set in CSS and go by the browser's own font size instead.
  • The usual ones are 640px = 40em, 768px = 48em, 1024px = 64em, 1280px = 80em, and 1536px = 96em. The numbers are the same in rem.

Print Stylesheets

  • Use physical units like pt, pc, cm, mm. These map directly to real-world print dimensions and ensure accurate printed output.

Icons and SVG

  • Use em when icons should scale with surrounding text (best for inline UI icons).
  • Use px when precise, fixed-size control is required (e.g., logos or tightly aligned UI elements).

Practical Use Cases of CSS Unit Conversions

Let's understand the above examples with practical use cases of CSS unit conversions because knowing the theory is one thing but actually knowing when to apply them in a real project is another.

Translating a Figma design to code

Most design tools, including Figma, use pixels as their default unit. So if a design specifies a heading size of 32px, but your project uses a rem-based typography system with a root font size of 16px, you simply divide 32 by 16 to get 2rem.

Converting your typography this way keeps your design consistent while allowing text to scale according to the user's browser settings automatically.

Scaling spacing from a pixel-based system

Suppose your design system defines a base spacing unit of 8px. To convert each value to rem, divide it by the root font size (typically 16px).

8px → 0.5rem

16px → 1rem

24px → 1.5rem

32px → 2rem

Using rem for spacing ensures that padding and margin scale proportionally if the root font size is ever adjusted. For instance, if you use the popular 62.5% root trick (making 1rem = 10px), the same 8px becomes 0.8rem.

Converting pixel widths to viewport units

Say you want a hero banner to fill exactly half the screen width on all devices. Your reference viewport is a 1920px wide artboard, and the hero section is 960px wide. To convert that width into vw, use the following calculation:

vw = (960 ÷ 1920) × 100 = 50vw

This means the hero section will always occupy 50% of the viewport width. Whether the user is viewing your site on a 375px phone or a 2560px desktop monitor, the element will continue to take up half of the available screen width.

Matching web typography to print specs

When creating a print stylesheet or generating a browser-based PDF, your designer may hand you type sizes in points (as is standard in tools like Adobe InDesign). For example, if the body text is specified as 12pt, you can convert it to pixels for comparison with your web styles:

px = 12 × (96 ÷ 72) = 16px

This demonstrates that 12pt is exactly equal to 16px, which is also the browser's default body text size. Knowing this relationship makes it easier to translate print typography into web styles while keeping text sizes consistent across both mediums.

Component spacing with em

Buttons, badges, and form controls often need padding that grows and shrinks as the text size changes. Suppose a button has a font-size of 14px and you want 10px of horizontal padding. You can convert the padding to em using:

em = 10 ÷ 14 ≈ 0.71em

Now if the button's font size changes (e.g., in a compact variant), the padding will adjust automatically, eliminating the need for separate overrides.

CSS Unit Tips, Tricks, and Best Practices

Let's move beyond the serious theory and practicals to explore a handful of small tricks that can save you significant conversion work. Each one works in all current browsers, and every value used here can be cross-checked with the Syntax Toolbox CSS Unit Converter.

The 62.5% root font size trick

There's a simple CSS trick for making px → rem conversions almost effortless. Just set the root font size to 62.5%.

Now 24px becomes 2.4rem, 8px becomes 0.8rem, and you can convert most values at a glance without reaching for a calculator.

CSS
html {
    font-size: 62.5%; /* 16px x 0.625 = 10px */
}

body {
    font-size: 1.6rem; /* back to 16px */
}

The trick is to use a percentage rather than hard-coding 10px. With html { font-size: 62.5%; }, the root size remains relative to the user's browser settings, so you get the convenient 10px baseline without unnecessarily overriding accessibility preferences.

One small catch: reset your body text to 1.6rem (or whatever base size you want). Otherwise, your default text will end up at 10px.

Fluid typography with clamp()

Tired of writing three media queries for one heading?

There's an easier way to make your typography scale smoothly. clamp() takes a minimum, a preferred value, and a maximum, then adjusts the font size fluidly between those limits as the viewport changes.

CSS
h1 {
    /* never below 28px, never above 56px */
    font-size: clamp(1.75rem, 1.25rem + 2.5vw, 3.5rem);
}

The trick is to keep a rem value in the middle expression. A preferred value made entirely of vw, such as 5vw, can stop text from growing on zoom, because zooming in shrinks the viewport in CSS pixels and the vw value shrinks with it. Mixing rem with vw gives you fluid sizing while still allowing the text to scale properly when users zoom the page.

Use ch to control line length

Long paragraphs can become surprisingly difficult to read when they stretch across the full width of a large screen. To keep them under control, try a CSS unit called ch.

1ch equals the width of the '0' character in the current font. Since a comfortable line length is usually around 60 to 75 characters, something like max-width: 65ch gives you a solid starting point.

CSS
.article-body {
    max-width: 65ch;
}

The trick is that ch is tied to the element's font. If you change the font family or size later, the measure adjusts with it. A fixed max-width in px would stay the same and might need manual retuning.

Fix the mobile 100vh problem with dvh

If you've ever built a full-screen section that looks perfect on desktop but gets cut off by the address bar on mobile, 100vh is usually the reason.

On mobile browsers, 100vh can be based on the largest possible viewport rather than the area currently visible on screen. 100dvh tracks the dynamic viewport instead, so the height adjusts as the browser's UI appears and disappears. That change can shift content while the user scrolls, so use svh if you need a steady height.

CSS
.hero {
    height: 100vh;  /* fallback for older browsers */
    height: 100dvh; /* wins wherever it is supported */
}

The trick is to declare both values: use 100vh as the fallback, then override it with 100dvh. Browsers that don't support dvh will ignore the second declaration and keep using the vh value.

Mix unit systems with calc()

Sometimes a layout needs to combine relative and absolute units, and that's where calc() comes in. You can mix units like %, vw, rem, and px in a single expression and eliminate guesswork from layout maths.

CSS
.main {
    /* full width minus a 20rem sidebar */
    width: calc(100% - 20rem);
}

.page {
    /* full screen minus a 4rem sticky header */
    min-height: calc(100vh - 4rem);
}

One small detail you must adhere to: keep spaces around the + and - operators. For example, calc(100%-20rem) is invalid, so the browser drops the entire declaration. The proper expression would be calc(100% - 20rem).

Frequently Asked Questions

A CSS unit converter translates a length from one CSS unit to another, such as px to rem or vw to px, using the reference value each relative unit depends on. Relative units have no fixed size on their own: 1.5rem is 24px only when the root font size is 16px, and 50vw is 720px only on a 1440px-wide screen. The Syntax Toolbox converter asks only for the reference a conversion needs (root font size, parent font size, parent element size, viewport size, or PPI) and shows the formula it applied.

Divide the pixel value by the root font size: rem = px ÷ root font size. With the browser default of 16px, 32px = 2rem, 24px = 1.5rem, and 14px = 0.875rem. If your stylesheet sets a different root size, divide by that instead: with html { font-size: 20px; }, 30px = 1.5rem. Enter your project's value in Base Font / REM Size, and the converter uses it for every rem result.

Multiply the rem value by the root font size: px = rem × root font size. At the default 16px, 1.5rem = 24px, 0.75rem = 12px, and 2.25rem = 36px. Because rem always refers to the html element, the same rem value gives the same pixel size anywhere on the page. To check a live page, inspect an element in your browser's developer tools and open the Computed tab, which lists the final size in pixels.

By default, 1rem = 16px, because 16px is the default font size in Chrome, Firefox, Safari, and Edge. It changes in two cases. A stylesheet can set its own root size, so html { font-size: 18px; } makes 1rem = 18px. A user can also raise the default font size in browser settings, for example to 20px, which makes 1rem = 20px unless the stylesheet fixes the root size in px. That second case is why rem is useful: layouts sized in rem grow with the reader's preference.

rem is always relative to the root (html) font size, so 2rem is the same size everywhere on a page. em is relative to the current context, and that context depends on the property. For font-size, 1em equals the parent element's font size. For other properties, such as padding, margin, and width, 1em equals the element's own font size, so a button with font-size: 20px and padding: 0.5em gets 10px of padding. em values also compound when nested: a list set to 1.2em inside another 1.2em list ends up 1.44 times the outer size. Use rem for consistent sizing, and em when spacing should scale with a component's own text.

Divide the pixel value by the font size that em refers to: em = px ÷ reference font size. For a font-size, the reference is the parent's font size; for padding, margins, and other properties, it is the element's own font size. With a 16px reference, 24px = 1.5em; with a 20px reference, the same 24px = 1.2em. Enter the reference in Parent Font / EM Size to get the right figure.

Because rem respects the reader's browser font size setting, and px does not. If someone with low vision raises their default font size from 16px to 24px, text set to 1rem grows to 24px, while text set to 16px stays at 16px. WCAG success criterion 1.4.4 requires that text can be resized up to 200% without loss of content; it does not mandate rem, but rem is the simplest way to honor font size settings, while browser zoom works with either unit. rem also makes global changes easy: change the root font size once and every rem value scales with it.

The root font size is what 1rem equals, so changing it rescales every rem value. Browsers default to 16px. The popular 62.5% trick, html { font-size: 62.5%; }, makes the root 10px (62.5% of 16px), so rem values read like pixels divided by ten: 1.6rem = 16px and 2.4rem = 24px. Because it uses a percentage rather than px, it still follows a user's font size setting. If you use the trick, set body text back to 1.6rem, and enter 10 in Base Font / REM Size when converting. Media query breakpoints are the exception: rem and em there ignore the stylesheet's root size, so keep 16. em values are set by the parent or element font size instead, which you enter in Parent Font / EM Size.

Divide the pixel value by the viewport width and multiply by 100: vw = px ÷ viewport width × 100. On a 1440px-wide screen, 360px = 25vw and 72px = 5vw. To go the other way, multiply: 10vw on a 390px-wide phone is 39px. The converter pre-fills Viewport Width with your current browser width, so change it to the screen you are designing for, such as 1920 for a full-HD desktop or 390 for a typical phone.

1vw is 1% of the viewport width, and 1vh is 1% of the viewport height. On a 1440 × 900 screen, 1vw = 14.4px and 1vh = 9px. Use vw for widths and fluid type that should track screen width, and vh for full-height sections such as a hero banner. On mobile, 100vh is measured as if the browser toolbars were hidden, so a 100vh section can be taller than the visible area; the dvh unit fixes this and has worked in all major browsers since late 2022. Note also that vw includes the vertical scrollbar, so width: 100vw can cause a small horizontal scroll on desktop.

They are viewport-height units built for mobile browser toolbars, which appear and disappear as you scroll. svh (small) is 1% of the height with the toolbars showing, lvh (large) is 1% of the height with them hidden, and dvh (dynamic) switches between the two as the toolbars move. On mobile, plain vh behaves like lvh. Use min-height: 100svh for a hero section that must never be cropped, and 100dvh when it should always fill the visible area, keeping in mind that dvh can shift the layout while scrolling. Matching width units (svw, lvw, dvw) exist too, and all are supported in Chrome, Edge, Firefox, and Safari. To convert them, use vh with the matching viewport height.

Divide the pixel value by the size of the parent element and multiply by 100: % = px ÷ parent size × 100. A 300px column inside a 1200px container is 25%, and 240px inside 960px is also 25%. The reference depends on the property: width, and also margin and padding on every side, use the parent's width, while height uses the parent's height, which must be set explicitly for a percentage height to work. Enter the container size in Parent Element Size.

In CSS, 1in is always 96px, and every physical unit follows from that: 1cm ≈ 37.8px, 1mm ≈ 3.78px, 1pt ≈ 1.333px (96 ÷ 72), and 1pc = 16px. So 2.5cm = 94.49px. On screen, these are not true physical sizes, because displays differ in pixel density and browsers scale the CSS pixel to suit each device; a CSS inch matches a real inch reliably only when printed. The converter uses 96 PPI by default to match CSS, so change PPI/DPI (Resolution) only when you need pixel counts at a specific resolution, such as 300 for print.

Use px (or rem) for screens and pt for print. The two are fixed to each other in CSS: 1pt = 1/72in and 1px = 1/96in, so 1pt = 1.333px, and 12pt is exactly 16px. That makes pt handy in @media print stylesheets and PDF generators, where designers think in point sizes such as 10pt body text and 24pt headings. On screen, pt has no advantage over px and, like px, ignores the reader's font size setting, so prefer rem for on-screen text.

Use clamp(minimum, preferred, maximum) with a preferred value that mixes rem and vw, so the size scales with screen width between two limits. For example, font-size: clamp(1rem, 0.75rem + 1.25vw, 1.5rem) gives 16px on a 320px-wide phone (12px + 4px), grows with the viewport, and stops at 24px from 960px wide. Keeping a rem part in the middle value means the text still responds to browser font size settings, which a vw-only value would not. Use the px to vw conversion to work out the vw part for your breakpoints.

Use rem for font sizes, spacing, and component sizes; % or fr for layout columns in flexbox and grid; vw, vh, or dvh for elements tied to the screen, such as full-height sections; and clamp() with rem and vw for fluid type. Keep px for borders, shadows, and fine details that should not scale. For media query breakpoints, em is the most reliable choice: 48em is 768px at the default font size and moves with the reader's setting. The ch unit, roughly the width of a "0", is useful for line length, for example max-width: 65ch.

Yes. Along with px, rem, em, %, vw, and vh, the converter handles the physical units used in print: pt (points), pc (picas), in, cm, and mm. For example, an A4 page is 210mm × 297mm, which is 793.7px × 1122.5px at the CSS standard of 96 PPI. Use mm or cm for page margins in an @page rule and pt for font sizes in print stylesheets. Set PPI/DPI (Resolution) to your output resolution, such as 300, when you need the pixel size of a print-ready image.

Yes. The converter is free, needs no sign-up, and runs entirely in your browser, so nothing you enter is uploaded. It converts between 11 CSS units, asks only for the reference values each conversion needs, and shows the calculation steps. Results are exact for the reference values you enter and are shown to up to four decimal places (very small values keep four significant figures instead), so 13px becomes 0.8125rem rather than a rounded 0.81rem.

We Value Your Opinion

Does this tool meet your expectations? Your feedback helps us improve

By submitting, you agree to our Terms of Use & Privacy Policy

Find Syntax Toolbox useful? Support us