Company Logo

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.

Enter a Value to Convert Between CSS Units

px
px
px
px
px
Converted value will appear here Copy result

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 documents. Choose the wrong unit and your carefully designed layout collapses on a high-DPI screen, disregards a user's browser font preference, or breaks in print. Make the right decision and your design flows seamlessly across phones, tablets, desktops, and even 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 streamlines your design process.

Understanding CSS Units at a Glance

Relative CSS Units

UnitSign usedDescription
Root EmremRelative to the root element's (html) font size.
EmemRelative to the font size of the parent element.
Percentage%Relative to the parent element's size.
Viewport Widthvw1% of the browser viewport's width.
Viewport Heightvh1% of the browser viewport's height.

Absolute CSS Units

UnitSign usedDescription
PixelspxPixel of the viewing device.
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: Choose Base Font/REM size.
  • Step 4: Enter a value to convert and check results in real-time.

No extra buttons. No delay. Just quick, accurate outputs.

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

Sr. No.Conversions betweenDefault 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 user's screen actual width
5Pixels to Viewport HeightViewport Height defaults to user's screen actual 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. Here, all relative-unit formulas assume the browser default of 16px for the root font size, 16px for the parent font size, and a 1920×1080px viewport unless you customise them in the tool.

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 × 1.333 ≈ 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

CSS Units in Real-World Web Layouts

Now that you've briefly understood how CSS units work, it's time to delve deeper and examine how each one behaves in real-world layouts. Because each CSS unit has its own scaling logic, strengths, and edge cases and knowing these is what separates a functional layout from a robust, responsive one.

Relative CSS Units Explained

Relative units are the backbone of any responsive and accessible web design 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: 16px;
}

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

.card {
    padding: 1.5rem; /* 1.5 x 16px = 24px */
}
  • The html element's font-size is 16px, 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 the computed font size of its closest parent element. If no font size is explicitly set, it 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 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 behaviour 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

The % unit is relative to the size of the parent element's corresponding property. Unlike em and rem, it is not limited to font size and can apply to width, height, padding, margins, and positioning.

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

CSS
.shell {
    width: 960px;
}

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

.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 to 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 centred, 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 to 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 behaviour. 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 at 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 a hairline at any zoom or 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 to 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.

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.

In web development, the size depends on the display's DPI setting rather than physical ruler inches.

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;
}

cm - Centimeters

Centimeters are a metric physical unit used to represent real-world length. In CSS, 1cm is defined as 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;
}

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 are the smallest absolute units, and it can serve developers working on everything ranging from web apps to browser-based PDF generation.

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

.business-card {
    width: 85mm;
    height: 55mm;
    border: 0.2mm dashed #999; /* fine cut guide, too small to express in cm */
}

Relative vs. Absolute CSS Units: Key Differences

Key DifferenceRelative UnitsAbsolute 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 size.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.
AccessibilityAdapts to user settings such as base font size, improving accessibility.Do not respond to user-defined browser setting, hindering accessibility.
ComputationRequire calculation based on context, which adds a small processing step.Values are fixed so rendering may be faster.

Choosing the Right CSS Unit for Your Layout

There are so many CSS units, how do you choose the right one for your specific layout? Instead of thinking in terms of individual units, start thinking in terms of what the value should respond to: the root, the parent, or the viewport. Once that decision is clear, the correct CSS unit will follow naturally.

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 overrides browser accessibility settings in older browsers.

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.

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:

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).

  • 8px0.5rem
  • 16px1rem
  • 24px1.5rem
  • 32px2rem

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. If your reference viewport is 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 × 1.333 ≈ 16px

This demonstrates that 12pt is approximately 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 override of values.

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 hack below is a production-safe pattern, not a workaround, 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 pxrem 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 break browser zoom because zooming doesn't change the viewport width in CSS pixels. 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.

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).

FAQs