Course contentsShow
← Web Development
Lesson 154 of 2,9823. CSS FundamentalsFree lesson

Absolute Units: px, pt, cm, mm, in

Learn pixel and other absolute length units, their use cases, and when fixed sizes make sense.

Absolute Units: px, pt, cm, mm, in

You'll learn what absolute length units are in CSS and when to use fixed sizes instead of flexible ones.

In CSS, you can specify sizes using absolute units — measurements that always represent the same physical or screen size, regardless of parent elements or user settings.

The Five Main Absolute Units

  • px (pixels): The most common unit. One pixel is typically one dot on your screen. width: 200px; means 200 screen pixels wide.
  • pt (points): Primarily for print. 1pt = 1/72 of an inch. Common in typography (font-size: 12pt;).
  • cm (centimeters): Physical measurement. margin: 2cm; gives roughly 2 centimeters on print.
  • mm (millimeters): Smaller physical unit. border: 5mm solid black;.
  • in (inches): 1in = 96px in CSS (or 2.54cm). Rarely used for screens.

When Fixed Sizes Make Sense

Think of absolute units like building with LEGO bricks of exact sizes — they don't stretch or shrink. Use them when:

  • You need precise control over borders (border: 2px solid black;)
  • Setting consistent icon sizes (width: 24px; height: 24px;)
  • Designing for print stylesheets (use pt, cm, mm)
  • Creating pixel-perfect UI elements like buttons or cards

However, pixels won't adapt to user preferences (like text scaling) or different screen sizes, so use them judiciously.

Pixels Are King on Screens

For web development, px dominates. The other units (pt, cm, mm, in) shine in print stylesheets but are awkward on screens because screen "inches" don't match physical inches perfectly.

Key Takeaway: Absolute units like px set fixed sizes that don't change — use pixels for precise screen layouts, but remember they won't adapt to user preferences or flexible layouts.