liveBook · Manning

Viewport unit

As explained in Web Design Playground, Second Edition

The vw unit is a CSS viewport-relative length unit equal to one percent of the viewport width.

The `vw` unit equals one percent of the current browser viewport’s width. Unlike a percentage, it measures against the whole viewport rather than an element’s parent. section 14.3

Use viewport units when sizing should respond to the screen itself:

  • Use `vw` for horizontal measures such as width, padding, or margins when they should scale with viewport width. section 14.11
  • Compare `vw` with `vh`, `vmin`, and `vmax`, which scale from viewport height or the smaller or larger viewport dimension. section 14.3

A quick viewport calculation

On a 1,600-pixel-wide viewport, `1vw` equals 16 pixels, so a value expressed in `vw` grows or shrinks with the browser width. section 14.3

How Web Design Playground, Second Edition covers it

How deep it goes
Explains viewport-relative sizing, numeric conversion, and percentage contrast without developing a complete vw implementation.
Examples
Uses a 1,600-pixel viewport calculation and contrasts a child sized at 75% of its parent with viewport-relative sizing.
What you can do after
Apply vw to horizontal measurements that need to scale with viewport width.
How it connects
Connects vw with percentage units, viewport units, vh, vmin, vmax, liquid layouts, and responsive web design.

Also explained in

Compare how 3 books explain viewport unit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.