CSS Values and Units

๐ŸŽจ CSS3+ ๐ŸŸข Chapter 10 of 49 ๐Ÿ“‚ Phase 04: Values, Units & Colors ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: px ยท % ยท em ยท rem ยท vw ยท vh ยท vmin ยท vmax ยท ch ยท ex ยท fr ยท deg ยท s ยท ms ยท Unitless ยท Choosing Units
Welcome to Chapter 10: CSS Values and Units โ€” part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
1CSS Values Overview

CSS properties ki values numbers, keywords, functions, or unit-suffixed measurements. Correct unit choose cheyadam responsive, accessible design ki critical.

UnitTypeUse Case
pxAbsoluteBorders, shadows, fixed icons
%RelativeParent-based width/height
emRelativeComponent-scoped scaling (parent font-size)
remRelativeRoot-based spacing & typography (recommended)
vw / vhViewportFull-screen sections, hero banners
vmin / vmaxViewportResponsive squares, min/max dimension
chCharacterReadable line length (~65ch)
frGrid fractionCSS Grid flexible columns
deg, s, msAnimationRotations, transition duration
2Absolute vs Relative Units
html { font-size: 16px; }

.container {
  width: 90%;
  max-width: 1200px;
  padding: 2rem;        /* 32px โ€” scales with root font */
  font-size: 1.125rem;  /* 18px */
}

.hero {
  min-height: 100vh;
  padding: 5vw 4vw;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
}
3Unitless Values & Choosing Correct Units

Some properties accept unitless values โ€” line-height: 1.5, opacity: 0.8, z-index: 10, flex: 1.

๐Ÿ’ก Unit Selection Guide
  • Typography & spacing: rem
  • Component-internal scaling: em
  • Layout widths: %, fr, max-width
  • Full viewport sections: vh, vw
  • Hairline borders: px
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy ยท CSS Complete Roadmap ยท Last updated August 2026