<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j" -->

---
title: CSS Units Explained: px, em, rem, %, vw, and clamp()
description: Every CSS unit is measured against something different, and rem is the right default for text. Pixels are fixed and ignore a person's browser font size...
canonical: https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: CSS Units Explained: px, em, rem, %, vw, and clamp() | daily.dev
og:description: Every CSS unit is measured against something different, and rem is the right default for text. Pixels are fixed and ignore a person's browser font size...
og:url: https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j
og:image: https://api.daily.dev/og/posts/FZx74046J.png
og:image:alt: CSS Units Explained: px, em, rem, %, vw, and clamp()
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

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

**[Kirupa](https://daily.dev/sources/kirupa)** · 12 min read · 0 upvotes · 0 comments

## Summary

Every CSS unit is measured against something different, and rem is the right default for text. Pixels are fixed and ignore a person's browser font size setting, while rem scales with it, so a 2rem heading becomes 40 pixels when they pick 20. Nested lists at 1.2em compound from 19.2 to 23.04 to 27.65 pixels, but 1.2rem stays at 19.2. On phones 100vh can slide under the toolbar, while 100svh always fits. clamp(1.5rem, 1rem + 3vw, 3rem) holds a heading between 24 and 48 pixels.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.kirupa.com/html5/css_units.htm>

## Questions this post answers

### Why should I use rem instead of px for font sizes in CSS?

A font-size in px ignores the default font size people set in their browser, while rem is measured against the root font size and scales with it. With a 20-pixel browser setting, a 2rem heading becomes 40 pixels. Unlike em, rem also never compounds in nested elements, so a 1.2rem nested list stays at 19.2 pixels per level.

_Developers who care about accessible text sizing follow CSS fundamentals like this on daily.dev._

### Why does my 100vh section get cut off by the toolbar on mobile browsers?

On phones, plain vh behaves like lvh, the large viewport height measured with toolbars hidden, so a 100vh section can end up with its bottom tucked under the toolbar. Use 100svh, measured with toolbars showing, so it always fits on screen. 100dvh also fits but changes size while scrolling, which can make the page jump.

_If mobile layout quirks keep surprising you, daily.dev keeps new CSS techniques in front of you._

### How does CSS clamp() work for fluid font sizes?

clamp() takes a minimum, a preferred value and a maximum, and uses the preferred value while it stays between the other two. With clamp(1.5rem, 1rem + 3vw, 3rem), the heading holds at 24 pixels below about 267 pixels of screen width and caps at 48 pixels past about 1,067. The rem in the preferred value keeps text responsive to zoom.

_Building responsive type that scales gracefully is a recurring topic for developers on daily.dev._

## Similar posts on daily.dev

- [7 modern CSS units your LLM keeps ignoring](https://daily.dev/posts/7-modern-css-units-your-llm-keeps-ignoring-pbazwuues) · RUBYLAND · 0 upvotes · 0 comments
- [Responsive and Fluid Typography with Baseline CSS Features](https://daily.dev/posts/responsive-and-fluid-typography-with-baseline-css-features-rnoepawxs) · OddBird · 4 upvotes · 0 comments
- [Death to px, long live ch\!](https://daily.dev/posts/death-to-px-long-live-ch--hw0sq1nxi) · Terence Eden · 6 upvotes · 6 comments
- [Why default Tailwind is not always an accessible choice](https://daily.dev/posts/why-default-tailwind-is-not-always-an-accessible-choice-efwxtqbfi) · Spatie · 50 upvotes · 5 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#css](https://daily.dev/tags/css), [#ui-design](https://daily.dev/tags/ui-design), [#accessibility](https://daily.dev/tags/accessibility)

[View this post on daily.dev](https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"CSS Units Explained: px, em, rem, %, vw, and clamp()","url":"https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j"},"datePublished":"2026-11-30T23:36:31.800Z","dateModified":"2026-11-30T23:36:52.162Z","description":"Every CSS unit is measured against something different, and rem is the right default for text. Pixels are fixed and ignore a person's browser font size...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5afaff5ae6569e7812c1169f571e0cc5?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5afaff5ae6569e7812c1169f571e0cc5?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Kirupa","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Kirupa","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/ff2fdb4927d34b81bd07cd18d6049a98","url":"https://daily.dev/sources/kirupa"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"webdev,css,ui-design,accessibility","timeRequired":"PT12M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kirupa","item":"https://daily.dev/sources/kirupa"},{"@type":"ListItem","position":3,"name":"CSS Units Explained: px, em, rem, %, vw, and clamp()"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/css-units-explained-px-em-rem-vw-and-clamp--fzx74046j#faq","mainEntity":[{"@type":"Question","name":"Why should I use rem instead of px for font sizes in CSS?","acceptedAnswer":{"@type":"Answer","text":"A font-size in px ignores the default font size people set in their browser, while rem is measured against the root font size and scales with it. With a 20-pixel browser setting, a 2rem heading becomes 40 pixels. Unlike em, rem also never compounds in nested elements, so a 1.2rem nested list stays at 19.2 pixels per level. Developers who care about accessible text sizing follow CSS fundamentals like this on daily.dev."}},{"@type":"Question","name":"Why does my 100vh section get cut off by the toolbar on mobile browsers?","acceptedAnswer":{"@type":"Answer","text":"On phones, plain vh behaves like lvh, the large viewport height measured with toolbars hidden, so a 100vh section can end up with its bottom tucked under the toolbar. Use 100svh, measured with toolbars showing, so it always fits on screen. 100dvh also fits but changes size while scrolling, which can make the page jump. If mobile layout quirks keep surprising you, daily.dev keeps new CSS techniques in front of you."}},{"@type":"Question","name":"How does CSS clamp() work for fluid font sizes?","acceptedAnswer":{"@type":"Answer","text":"clamp() takes a minimum, a preferred value and a maximum, and uses the preferred value while it stays between the other two. With clamp(1.5rem, 1rem + 3vw, 3rem), the heading holds at 24 pixels below about 267 pixels of screen width and caps at 48 pixels past about 1,067. The rem in the preferred value keeps text responsive to zoom. Building responsive type that scales gracefully is a recurring topic for developers on daily.dev."}}]}
```

