X Xerobit

PX to REM Conversion — Formula, Table, and CSS Custom Properties

Convert pixel values to rem using the formula rem = px / base-font-size. Includes a quick reference table for common values, the 62.5% root font-size trick, and how to use CSS...

Mian Ali Khalid · · 4 min read
Use the tool
Pixel to REM Converter
Convert px to rem, em, and percent — and vice versa. Configurable root font size. Bulk conversion mode for entire stylesheets.
Open Pixel to REM Converter →

The rem unit is relative to the root (<html>) font size. The default browser root font size is 16px. Converting px to rem: divide by the root font size.

Use the PX to REM Converter to convert values instantly.

The formula

rem = px ÷ root-font-size

Default root font size = 16px:
16px  ÷ 16 = 1rem
24px  ÷ 16 = 1.5rem
32px  ÷ 16 = 2rem
14px  ÷ 16 = 0.875rem
12px  ÷ 16 = 0.75rem

Common px to rem conversion table (base 16px)

pxrem
8px0.5rem
10px0.625rem
12px0.75rem
14px0.875rem
16px1rem
18px1.125rem
20px1.25rem
24px1.5rem
28px1.75rem
32px2rem
40px2.5rem
48px3rem
64px4rem
80px5rem
96px6rem

The 62.5% trick

Set root font size to 62.5% so 1rem = 10px — easier mental math:

html {
  font-size: 62.5%;  /* 10px = 1rem */
}

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

/* Now rem values are intuitive: */
h1 { font-size: 3.2rem; }   /* 32px */
p  { font-size: 1.6rem; }   /* 16px */
small { font-size: 1.2rem; } /* 12px */

With 62.5%:

pxrem
10px1rem
12px1.2rem
14px1.4rem
16px1.6rem
20px2rem
24px2.4rem
32px3.2rem

Note: This approach still respects user browser font size preferences because 62.5% is relative to the user’s base size.

CSS custom property approach

:root {
  --base: 16;  /* Base font size in px (number only) */
  
  /* Define common sizes as rem: */
  --text-xs:   0.75rem;    /* 12px */
  --text-sm:   0.875rem;   /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-lg:   1.125rem;   /* 18px */
  --text-xl:   1.25rem;    /* 20px */
  --text-2xl:  1.5rem;     /* 24px */
  --text-3xl:  1.875rem;   /* 30px */
  --text-4xl:  2.25rem;    /* 36px */
  
  --space-1:   0.25rem;    /* 4px  */
  --space-2:   0.5rem;     /* 8px  */
  --space-3:   0.75rem;    /* 12px */
  --space-4:   1rem;       /* 16px */
  --space-6:   1.5rem;     /* 24px */
  --space-8:   2rem;       /* 32px */
  --space-12:  3rem;       /* 48px */
  --space-16:  4rem;       /* 64px */
}

h1 { font-size: var(--text-4xl); }
p  { font-size: var(--text-base); line-height: 1.6; }
section { padding: var(--space-8); }

SCSS function for conversion

$root-font-size: 16;

@function rem($px) {
  @return #{$px / $root-font-size}rem;
}

// Usage:
h1 { font-size: rem(32); }  // 2rem
p  { font-size: rem(16); }  // 1rem
.card { padding: rem(24) rem(32); }  // 1.5rem 2rem

// Or as mixin:
@mixin font-size($px) {
  font-size: #{$px / $root-font-size}rem;
}

CSS calc() for dynamic conversion

/* If you know the base and want to compute: */
/* Note: CSS can't do rem division natively without preprocessors */
/* But calc() works for combining values: */

.component {
  /* 24px + 8px = 2rem: */
  padding: calc(1.5rem + 0.5rem);
  
  /* Mix units: */
  margin: calc(2rem - 4px);
}

Accessibility: why rem beats px for fonts

/* User sets browser font to 20px (accessibility need) */

/* px ignores user preference: */
h1 { font-size: 32px; }  /* Still 32px — user preference ignored */

/* rem respects it: */
h1 { font-size: 2rem; }  /* 40px — scales with user's 20px base */

This is why WCAG recommends using relative units for font sizes.


Related posts

Related tool

Pixel to REM Converter

Convert px to rem, em, and percent — and vice versa. Configurable root font size. Bulk conversion mode for entire stylesheets.

Written by Mian Ali Khalid. Part of the Frontend & Design pillar.