CSS rem / % / vw
- type
- unit
- applies to
- anywhere a length is expected
- inherits
- n/a
- common values
- rem (root font size), % (parent), vw/vh (viewport)
Where it goes
Anywhere a fixed px value would fight a reader's settings or a different screen size.
Example
.container {
width: 90%;
max-width: 60rem;
padding: 2vw;
}Common mistakes
- Using em instead of rem for text sizes inside nested tags. em multiplies through every parent, so sizes drift as nesting gets deeper.
- Setting width: 100vw on a page that has a vertical scrollbar. 100vw includes the scrollbar's width, so the page gets a small sideways scroll.