How to use the viewBox attribute?

The width and height are how big the <svg> is. The viewBox controls how its contents are displayed so the viewBox=”0 0 1500 1000″ will scale down the contents of <svg> element by a factor of 5 (1500 / 300 = 5 and 1000 / 200 = 5) and the contents will be 1/5 the size they would be without the viewBox but the <svg>

Imagine you have an elastic surface and cut it into 4 equal pieces. If you throw 3 pieces away you’ve got a surface that’s 1/4 the size of the original surface. If you now stretch the surface and make it the same size as the original surface then everything on the surface will be twice the size. That’s how viewBox and width/height are related.

Leave a Comment