liveBook · Manning

Viewbox attribute

The SVG viewBox attribute defines the origin and dimensions of an internal coordinate system and maps it to the viewport.

How 2 Manning books explain it

D3.js in Action, Third Edition

The viewBox attribute defines the coordinate-system origin, width, and height used to map SVG content into its viewport.

How it is used
Makes SVG charts responsive while preserving the intended aspect ratio inside a constrained container.
How deep it goes
Defines all four values and demonstrates setting the attribute in HTML and with D3, without further rendering internals.
Examples
Uses a 900-by-300 SVG shapes gallery and a 1200-by-1600 responsive bar-chart container.
What you can do after
Apply it via D3’s attr() method or SVG markup to create a responsive, proportionally scaled drawing area.

Read how D3.js in Action, Third Edition explains viewbox attribute →

Tiny CSS Projects

The SVG viewBox attribute defines the position and dimensions of an SVG graphic's internal coordinate system and maps it to the viewport.

How it is used
Uses the viewBox to make an SVG loading graphic scale with its responsive container.
How deep it goes
Explains syntax, coordinate positioning, dimension calculations, zoom behavior, and responsive resizing through a worked loader.
Examples
Demonstrates an animated loading screen containing eleven evenly spaced SVG rectangles.
What you can do after
Build a responsive SVG graphic by choosing coordinate-space dimensions and applying a viewBox attribute.

Read how Tiny CSS Projects explains viewbox attribute →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.