Using the viewBox
You saw earlier how an SVG document is similar to a bulletin board. Taking this analogy a step further, suppose you have five separate notes pinned in different locations on the bulletin board. However, rather than letting your audience see the entire bulletin board at one time, you decide they should see only one of the notes on the board. To achieve this sort of “peephole” view, the svg element uses an attribute called the viewBox.
As mentioned earlier, the top left corner of the SVG document is the (0,0) point. The viewBox honors the coordinates of a file's content but adjusts the display to match its coordinates. To do this, the viewBox has four values, each separated by a comma or a space. The first two values specify the ...
Get Sams Teach Yourself SVG in 24 Hours now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.