Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Units of Measurement | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 9 of 50

·css

Units of Measurement

8 mins

Course progress18%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `rem` is the preferred unit for spacing and font‑size because it stays consistent across the document.
  • `vw`/`vh` are perfect for fluid, full‑screen designs.
  • Avoid mixing `px` with `em`/`rem` for the same dimension; pick one system.

CSS offers a palette of units. Choosing the right one determines how responsive and maintainable your layout will be.

1. Absolute Units – rarely used for responsive UI

  • px – pixel (device‑independent). Most designers think in pixels.
  • pt, cm, mm, in – print‑oriented; useful only for print stylesheets.

2. Relative Units – the workhorses of modern web design

UnitRelative toWhen to use
emParent element’s font-size.Component‑level scaling (e.g., button padding that grows with its container’s font size).
remRoot (<html>) font-size.Global spacing, typographic rhythm, whole‑site scaling.
%Parent’s width/height (depending on the property).Fluid widths, heights, or line‑height percentages.

3. Viewport Units – perfect for full‑screen layouts

UnitDefinition
1vw1 % of the viewport width.
1vh1 % of the viewport height.
vminSmaller of vw or vh.
vmaxLarger of vw or vh.

Example – Full‑Height Hero Section

.hero {
  height: 100vh;           /* 100 % of viewport height */
  display: flex;
  align-items: center;
  justify-content: center;
  background: #222;
  color: #fff;
}

Pro Tip – Mixing Units

Never mix px with em/rem on the same property. It creates a mental overhead and can lead to unexpected scaling. Stick to a single‑system per project (e.g., rem‑based spacing everywhere, vw for fluid typography).

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonTypography BasicsContinue to lesson 10Display PropertyBack to CSS Basics to Advanced curriculum