Viewbox attribute
The SVG viewBox attribute specifies the position and dimensions of an internal coordinate system that is mapped to the graphic’s viewport.
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.
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.
What to know first
- viewportA viewport is the visible region of a browser or graphical interface in which a document or other content is displayed.
- CSSCSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- SVGSVG (Scalable Vector Graphics) is an XML-based standard and markup language for describing scalable two-dimensional vector graphics.
Related concepts
- responsive SVGconfigures · A responsive SVG is an SVG graphic whose rendered size adapts to its containing element while preserving its intended coordinate relationships and aspect ratio.
- viewportconfigures · A viewport is the visible region of a browser or graphical interface in which a document or other content is displayed.
- SVGconfigures · SVG (Scalable Vector Graphics) is an XML-based standard and markup language for describing scalable two-dimensional vector graphics.
- responsive data visualizationconfigures · A responsive data visualization adapts its layout or presentation to different screen sizes and interaction contexts.
- SVG elementpart of · An SVG element is a markup element in an SVG document that defines or contributes to vector graphics.
- loading indicatorconfigures · A loading indicator is a user-interface element that signals an ongoing operation, such as loading, initialization, or data retrieval.
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.


