liveBook · Manning

Viewbox attribute

The SVG viewBox attribute specifies the position and dimensions of an internal coordinate system that is mapped to the graphic’s viewport.

How 3 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
Keeps SVG shape galleries and bar charts proportional as their containers resize.
How deep it goes
Defines all four values and walks through fixed, percentage-width, and viewBox sizing without exploring other SVG fitting controls.
Examples
Uses a 900-by-300 SVG shapes gallery and a bar chart with viewBox="0 0 1200 1600".
What you can do after
Apply it via SVG markup or D3’s attr() method to preserve proportions while an SVG adapts to its container.

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

HTML5 in Action

The SVG viewBox attribute defines the position and dimensions of the coordinate system used to display content within a viewport.

How it is used
Uses viewBox to give an SVG game a flexible viewing window while retaining its drawing coordinates.
How deep it goes
Explains the four values and walks through configuration and testing, but recommends experimentation to understand resizing.
Examples
Configures a 500-by-500 game viewport and suggests a manual offset for misplaced vector artwork.
What you can do after
Operate/configure an SVG viewBox for a flexible game layout and experiment with offsets for misplaced artwork.

Read how HTML5 in Action 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 →

What to know first

Related concepts

Questions about viewbox attribute

What is viewbox attribute?

The SVG viewBox attribute specifies the position and dimensions of an internal coordinate system that is mapped to the graphic’s viewport.

Which Manning books explain viewbox attribute?

D3.js in Action, Third Edition, HTML5 in Action and Tiny CSS Projects.

What should I know before learning viewbox attribute?

Manning books that teach viewbox attribute usually introduce viewport, CSS and SVG first.

What is viewbox attribute part of?

Viewbox attribute is part of SVG element. An SVG element is a markup element in an SVG document that defines or contributes to vector graphics.

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.