CSS Units Reference

Complete reference of all CSS units and measurements

About This Reference

This comprehensive reference lists all CSS units organized by category. Units define measurements for lengths, angles, time, resolution, and percentages. Understanding units is essential for creating responsive, accessible designs.

Each unit includes a description and link to the official W3C specification. Click section headings to view related tutorials with practical examples.

Absolute Length Units

Unit Description Links
px Pixels - reference pixel (1/96th of 1 inch), not physical pixels
cm Centimeters - 1cm = 96px/2.54
mm Millimeters - 1mm = 1/10th of 1cm
q Quarter-millimeters - 1q = 1/40th of 1cm (precise print work)
in Inches - 1in = 2.54cm = 96px
pt Points - 1pt = 1/72nd of 1in (used in print)
pc Picas - 1pc = 1/6th of 1in = 12pt

Font-Relative Length Units

Unit Description Links
em Relative to parent element's font-size (compounds)
rem Relative to root (html) font-size (typically 16px)
ex Height of lowercase x in element's font
ch Width of "0" character in element's font (useful for monospace)
cap Height of capital letters in element's font
ic Width of "水" (CJK water ideograph) in element's font
lh Line height of the element
rlh Line height of the root element

Dynamic Viewport Units

Unit Description Links
dvh Dynamic viewport height - adjusts as mobile browser UI shows/hides
dvw Dynamic viewport width
svh Small viewport height - assumes browser UI is shown (smallest)
svw Small viewport width
lvh Large viewport height - assumes browser UI is hidden (largest)
lvw Large viewport width
dvi Dynamic viewport inline dimension
dvb Dynamic viewport block dimension
svmin Small viewport smaller dimension (min of svw/svh)
svmax Small viewport larger dimension (max of svw/svh)
lvmin Large viewport smaller dimension (min of lvw/lvh)
lvmax Large viewport larger dimension (max of lvw/lvh)
dvmin Dynamic viewport smaller dimension (min of dvw/dvh)
dvmax Dynamic viewport larger dimension (max of dvw/dvh)

Container Query Length Units

Unit Description Links
cqw 1% of query container's width
cqh 1% of query container's height
cqi 1% of query container's inline size (most useful)
cqb 1% of query container's block size
cqmin 1% of query container's smaller dimension
cqmax 1% of query container's larger dimension

Grid Layout Units

Unit Description Links
fr Flexible fraction - distributes remaining space proportionally in grid tracks

Angle Units

Unit Description Links
deg Degrees - full circle = 360deg (most common)
rad Radians - full circle = 2π rad (≈ 6.2832rad)
grad Gradians - full circle = 400grad
turn Turns - full circle = 1turn (most intuitive)

Time Units

Unit Description Links
s Seconds - used in transitions and animations
ms Milliseconds - 1000ms = 1s

Resolution Units

Unit Description Links
dpi Dots per inch - used in media queries for screen density
dpcm Dots per centimeter
dppx Dots per pixel unit (1dppx = 96dpi, matches device pixel ratio)

Percentage Unit

Unit Description Links
% Percentage - relative to parent element's corresponding property

Best Practices

Choosing the right unit is crucial for creating responsive, accessible designs. Different units serve different purposes, and understanding when to use each improves your layouts and user experience.

Unit Selection Guidelines

  • Font sizing: Use rem to respect user font preferences and avoid compounding issues with em
  • Component spacing: Use em for padding and margins within components to maintain proportions when font size changes
  • Line width: Use ch for maximum line width - 45-75ch creates readable text blocks
  • Full-height layouts: Use dvh instead of vh on mobile to account for browser UI (address bar, toolbars)
  • Container components: Use cqi or cqw for truly modular, container-based responsive design
  • Borders and outlines: Use px for crisp 1px or 2px borders that don't scale unnecessarily
  • Print stylesheets: Use absolute units (pt, cm, in) for predictable physical dimensions
  • Rotations: Use turn for intuitive rotation values (0.25turn = 90deg, 0.5turn = 180deg)
  • Animations: Use ms for precise timing control, s for readability with longer durations
  • Avoid mixing: Stay consistent - don't mix px and rem randomly within the same component

Common Patterns

Use Case Recommended Unit Reason
Body font size 100% or 1rem Respects user's browser default
Heading sizes rem Scales with user preferences
Button padding em Scales with button's font size
Max content width ch or rem Creates readable line lengths
Hero section height dvh Adapts to mobile browser UI
Card component cqi Responds to container, not viewport
Transition duration ms Precise control (200ms, 350ms)
Border width px Crisp, fixed-size borders

Resources & Tools

Demo