liveBook · Manning

Dimension

As explained in Math for Web Design

An axis is a reference direction in a coordinate system along which a component or position is measured.

A dimension is an axis: a reference direction along which a position or component is measured. In a browser, a two-dimensional viewport uses a horizontal x-axis and a vertical y-axis. Their intersection is the origin, normally the viewport’s top-left corner. section 1.4.9

Dimensions make frontend positions calculable. Positive x values move right, positive y values move down, and pixels are the default unit. Negative values and values beyond the viewport are valid, so an element can sit partly or entirely outside the visible area. section 1.4.9

The same idea appears in several frontend calculations:

  • CSS Grid treats columns as one dimension and rows as another; their intersections form placement cells. section 4.1.2
  • LAB color uses three dimensions: lightness, green–red, and blue–yellow, allowing color differences to be described numerically. section 7.1.3
  • A movement vector uses x and y dimensions to describe displacement, direction, and distance. section 10.1

A full-viewport hero

Set one dimension to the viewport width and the other to its height: .hero { width: 100vw; height: 100vh; }. The element then scales across both viewport axes. section 1.4.9

Table 1.9 Some uses of coordinate systems in CSS and JavaScript

Task

Code

Explanation

Get an element’s current viewport position in JavaScript.

const rect = element
.getBoundingClientRect();

The getBoundingClient­Rect()method returns the positions of an element’s top, right, bottom, and left sides relative to the viewport origin.

Return the mouse pointer’s current viewport position in JavaScript.

window.addEventListener("mousemove", (e) => {

console.log(e.clientX, e.clientY);

});

For a mousemove event e, the properties e.clientX and e.clientY represent the pointer’s current position relative to the viewport’s origin.

Scale a heading based on the viewport width in CSS.

h1 { font-size: 5vw; }

As the viewport widens or narrows, the font size of each h1 heading will grow or shrink proportionately.

Use the coordinate-system table to connect dimensions with getBoundingClientRect(), mouse coordinates, and viewport-responsive font sizing. section 1.4.9

How Math for Web Design covers it

How deep it goes
Defines axes through viewport, grid, color, and vector examples, but stops short of a general mathematical treatment.
Examples
Uses viewport positioning, CSS Grid cells, LAB color axes, viewport-sized heroes, and two-dimensional movement vectors.
What you can do after
Apply it via CSS and JavaScript to reason about positions, responsive sizes, grid placement, colors, and movement.
How it connects
Connects dimensions with coordinate systems, CSS Grid, vectors, bounding boxes, viewport units, and LAB color space.

Also explained in

Compare how 8 books explain dimension →

Related concepts

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