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.
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.
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.
You now have a complete CSS units list in table format with absolute units,
relative units, viewport units, container query units, angle units, time units,
resolution units, examples, accessibility tips, SEO benefits, best practices,
and common mistakes.