← Back to CSS
09

CSS Units: px, rem, %, vw and clamp()

Master absolute and relative units to create flexible and readable designs.

📘 Theory

Quick units map

What to use and when to avoid rigid designs.

Absolute units like px are predictable, but do not scale well on screens and user preferences.

Relative units (rem, em, %, vw, vh, fr) adapt to context and make the design breathe better.

  • px: useful for borders and shadows, avoid in typography.
  • rem: global scale, ideal base for text.
  • em: local scale, perfect for components.
  • %: depends on container, useful for widths and paddings.
  • vw/vh: relative to viewport, useful for hero and layouts.
  • fr: Grid unit representing a fraction of available space.
  • ch: useful for inputs and monospace.
  • min()/max()/clamp(): limits and fluid sizes.

rem and em: the base of a good scale

Define a base and everything grows coherently.

1

With rem you can define a consistent typographic scale for the entire site.

2

With em you can adjust sizes within a component without breaking the rest of the design.

Fluid sizes with clamp()

Avoid abrupt jumps in responsive.

1

clamp() allows you to define a minimum size, a preferred one and a maximum.

2

It is ideal for titles that should grow smoothly between mobile and desktop.

When to use each CSS unit

🧭 Key visuals

CSS units reference

Quick guide to choose the appropriate unit according to context.

Comparison of units px, rem, em, vw, vh and percentage.

Additional CSS units comparison

Visual complement to choose units according to typography, layout and viewport.

Practical relationship between relative and absolute units in different contexts.

🧪 Learn by doing

Example Typographic scale with rem Create a hierarchy of titles with rem.
Example Fluid card Use % and clamp() for a flexible layout.

🏁 Challenges

Challenge Challenge: fluid title Define an h1 with clamp() and rem base.

🧰 Resources

Test

Check your knowledge with a test about CSS.

Test for CSS

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com