Skip to content

CSS Units List

CSS units define sizes, spacing, typography, layouts, animation timing, rotation, resolution, and responsive behavior. This complete CSS units list explains absolute, relative, viewport, font-relative, container query, angle, time, and resolution units with examples and best practices.

What Are CSS Units?

CSS units are values used with CSS properties to define measurements. For example, you can use units to set width, height, margin, padding, font size, border radius, animation duration, rotation angle, and more.

.card {
  width: 100%;
  max-width: 720px;
  padding: 1rem;
  font-size: 1rem;
  border-radius: 0.75rem;
}

In this example, %, px, and rem are CSS units.

CSS Units List in Table Format

Category Unit Example Purpose
Absolute Lengthpxfont-size: 16px;Pixels; commonly used for borders, icons, and precise sizes.
Absolute Lengthptfont-size: 12pt;Points; mostly used for print styles.
Absolute Lengthpcwidth: 10pc;Picas; mostly used in print typography.
Absolute Lengthinwidth: 1in;Inches; useful mainly in print CSS.
Absolute Lengthcmwidth: 5cm;Centimeters; mostly useful for print layouts.
Absolute Lengthmmwidth: 50mm;Millimeters; mostly useful for print layouts.
Absolute LengthQwidth: 40Q;Quarter-millimeters; used in specialized print sizing.
Relative Length%width: 100%;Relative to the parent or relevant reference size.
Relative Lengthempadding: 1em;Relative to the current element font size.
Relative Lengthremfont-size: 1rem;Relative to the root element font size.
Relative Lengthchmax-width: 65ch;Relative to the width of the “0” character; useful for readable text width.
Relative Lengthexheight: 2ex;Relative to the x-height of the font.
Relative Lengthlhmargin-top: 1lh;Relative to the element line height.
Relative Lengthrlhmargin-bottom: 1rlh;Relative to the root element line height.
Viewportvwwidth: 100vw;1% of viewport width.
Viewportvhmin-height: 100vh;1% of viewport height.
Viewportvminfont-size: 5vmin;1% of the smaller viewport dimension.
Viewportvmaxfont-size: 5vmax;1% of the larger viewport dimension.
Small Viewportsvwwidth: 100svw;1% of small viewport width.
Small Viewportsvhmin-height: 100svh;1% of small viewport height; useful on mobile browsers.
Large Viewportlvwwidth: 100lvw;1% of large viewport width.
Large Viewportlvhmin-height: 100lvh;1% of large viewport height.
Dynamic Viewportdvwwidth: 100dvw;1% of dynamic viewport width.
Dynamic Viewportdvhmin-height: 100dvh;1% of dynamic viewport height; adapts to browser UI changes.
Container Querycqwwidth: 50cqw;1% of query container width.
Container Querycqhheight: 50cqh;1% of query container height.
Container Querycqifont-size: 5cqi;1% of query container inline size.
Container Querycqbpadding: 5cqb;1% of query container block size.
Container Querycqminfont-size: 4cqmin;1% of the smaller query container dimension.
Container Querycqmaxfont-size: 4cqmax;1% of the larger query container dimension.
Angledegrotate: 45deg;Degrees; common for rotation and gradients.
Angleradrotate: 3.14rad;Radians; useful in mathematical rotation values.
Anglegradrotate: 100grad;Gradians; less commonly used angle unit.
Angleturnrotate: 0.5turn;Turns; 1turn equals a full rotation.
Timesanimation-duration: 1s;Seconds; used for animations and transitions.
Timemstransition-duration: 200ms;Milliseconds; common for UI interaction timing.
Resolutiondpi@media (min-resolution: 300dpi)Dots per inch; used in resolution media queries.
Resolutiondpcm@media (min-resolution: 118dpcm)Dots per centimeter.
Resolutiondppx@media (min-resolution: 2dppx)Dots per CSS pixel; useful for high-density displays.
FrequencyHzfrequency: 440Hz;Hertz; rarely used in normal CSS.
FrequencykHzfrequency: 1kHz;Kilohertz; rarely used in normal CSS.
Gridfrgrid-template-columns: 1fr 2fr;Fraction of available grid space.
Unitless0margin: 0;Zero does not need a unit.
Unitlessline-heightline-height: 1.6;Unitless line-height scales with font size.
Unitlessopacityopacity: 0.8;Uses a number between 0 and 1.
Unitlessz-indexz-index: 10;Controls stacking order with integer values.
Unitlessfont-weightfont-weight: 700;Uses numeric weight values.

Absolute Units vs Relative Units

CSS units are commonly grouped into absolute and relative units.

Type Examples Best Use
Absolute Units px, pt, cm, mm, in Precise sizes, borders, print layouts, and fixed UI details.
Relative Units %, em, rem, vw, vh, fr Responsive layouts, scalable typography, spacing, and flexible components.

For modern responsive websites, relative units are usually preferred for spacing, typography, and layout sizing.

Most Used CSS Units for Beginners

  • px: useful for borders, icons, and small fixed details.
  • %: useful for flexible widths and responsive layouts.
  • rem: useful for consistent font sizes and spacing.
  • em: useful when spacing should scale with the current text size.
  • vw and vh: useful for viewport-based layouts.
  • fr: useful for CSS Grid column and row sizing.
  • ch: useful for readable text line lengths.

Responsive CSS Unit Examples

.container {
  width: min(100% - 2rem, 1200px);
  margin-inline: auto;
}

.article {
  max-width: 65ch;
  line-height: 1.7;
}

.hero-title {
  font-size: clamp(2rem, 6vw, 4.5rem);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

Viewport Units and Mobile Browsers

Traditional vh can behave unexpectedly on mobile browsers because browser toolbars can appear and disappear. Modern viewport units help solve this issue.

  • svh: small viewport height.
  • lvh: large viewport height.
  • dvh: dynamic viewport height.
.hero {
  min-height: 100dvh;
}

Use dvh when a layout should adapt as mobile browser UI changes.

Container Query Units

Container query units size elements based on the nearest query container instead of the viewport. They are useful for component-based responsive design.

.card-wrapper {
  container-type: inline-size;
}

.card-title {
  font-size: clamp(1rem, 6cqi, 2rem);
}

In this example, the title size responds to the component container width.

CSS Units and Accessibility

  • Use relative units like rem for scalable text and spacing.
  • Avoid fixed heights that cut off content when users zoom or increase font size.
  • Use readable line lengths with ch.
  • Use unitless line-height for better text scaling.
  • Test layouts at 200% zoom and mobile screen sizes.
  • Avoid using viewport units in ways that trap or hide content on mobile.

CSS Units and SEO

CSS units do not directly improve rankings, but they affect responsive design, readability, accessibility, layout stability, and page experience.

  • Responsive units improve mobile-friendly layouts.
  • Readable font and spacing units improve content consumption.
  • Stable layout sizing can support better Core Web Vitals.
  • Accessible units support users who zoom or customize text size.
  • Flexible units make websites easier to maintain across devices.

Common CSS Unit Mistakes

  • Using fixed pixel widths that break mobile layouts.
  • Using vh without testing mobile browser toolbar behavior.
  • Setting fixed heights on text containers and cutting off content.
  • Using em deeply without understanding compounding behavior.
  • Using too many different unit types without a system.
  • Forgetting that 0 does not need a unit.
  • Using small fixed font sizes that do not scale well.

CSS Unit Best Practices

  • Use rem for most font sizes and spacing tokens.
  • Use %, fr, and minmax() for flexible layouts.
  • Use px for borders, icons, and very small fixed details.
  • Use ch for readable text width.
  • Use clamp() with viewport units for fluid typography.
  • Use dvh carefully for mobile-friendly full-height layouts.
  • Use unitless line-height.
  • Build a consistent spacing and sizing scale.
  • Test units across mobile, tablet, desktop, zoom, and text scaling.

Key Takeaways

  • CSS units define measurements for layout, typography, spacing, animation, and more.
  • Absolute units include px, pt, cm, mm, and in.
  • Relative units include %, em, rem, vw, vh, ch, and fr.
  • Modern viewport units include svh, lvh, and dvh.
  • Container query units include cqw, cqh, cqi, and cqb.
  • Use relative units for responsive and accessible websites.

Pro Tip

For most modern websites, use rem for typography and spacing, % and fr for flexible layouts, ch for readable text, and clamp() for fluid responsive sizing.