px

The CSS pixel: the anchor that the other absolute units are measured in.

Safe to useBaseline: widely available

First version with support, from MDN browser data
BrowserSince
Chrome1+
Chrome Android18+
Edge12+
Firefox1+
Firefox Android4+
Safari1+
Safari iOS1+

Formula 1px = 1/96in

How it works

The CSS pixel is the unit the rest of the absolute family comes down to. An inch is defined as exactly 96 of them, and the point, pica, centimeter, millimeter and quarter-millimeter are each a fixed fraction of that inch, so every absolute length is a fixed number of CSS pixels. Nothing in this chain touches the screen in front of you. The specification ties the pixel to a reference pixel, the angle that one pixel of a 96 dpi screen covers in the eye at arm’s length, and the idea behind that definition is that one px should look about the same size on a phone, a laptop and a television.

Lengths in a stylesheet are counted in CSS pixels. The hardware shows up only at the last step, where the browser maps each CSS pixel onto as many device dots as it needs: a 2×2 block on a display with a device pixel ratio of 2, half a dot across at a ratio of 0.5. A box of 100px measured 100 CSS pixels at every ratio from 0.5 to 3 in Chromium, so a change in the ratio changes how many dots a px covers while every px value in your stylesheet stays the same.

A length in px knows nothing about the reader’s text settings. Ask for 16px and you get 16px, whatever default font size the browser has been told to use: in Chromium with the default raised to 24px, 1rem became 24px while 1px, 1pt and 1in stayed as they were. Keep it for things that should hold still: hairlines, shadows, the box around an icon with a fixed bitmap behind it.

Try it

Convert between the absolute units

Type a length in one unit and read it in all seven. Every absolute unit is a fixed number of CSS pixels, so the conversion needs no screen.

px
96
pt
72
pc
6
in
1
cm
2.54
mm
25.4
Q
101.6
The same as a table
How many CSS pixels one of each absolute unit is
UnitCSS pixels in 1 of it
1px1px
1pt1.3333px
1pc16px
1in96px
1cm37.795px
1mm3.7795px
1Q0.94488px

What changes it

Moves with
  • page zoom
Stays put under
  • the reader's text size
  • the window size
  • the font in use
  • the query container
  • phone toolbars
  • the writing mode

Reach for it when

Hairlines, shadows and the box around a fixed bitmap: details that should hold still while the text around them scales.

Watch out

A CSS pixel is not a screen pixel. On a 2x display one px covers 2×2 device pixels, and page zoom changes that ratio too. Text in px still grows with page zoom, but it ignores the default font size set in browser settings.

Example The text moves to rem and follows the reader; the hairline stays in px and holds still.

Before

.card {
  font-size: 14px;
  border: 1px solid;
}

After

.card {
  font-size: 0.875rem;
  border: 1px solid;
}

MDN (opens in a new tab)Specification (opens in a new tab)