How exactly does viewBox work when you haven't added width and height to your SVG? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How exactly does viewBox work when you haven't added width and height to your SVG?

I know how viewbox works, but when I use it without adding width and height to my SVG for some reason the viewport becomes huge, and I don't mind it, I can easily fix it by adding the width and height attributes, however, I'm curious to understand why it behaves this way, and why does somebody use the viewbox this way? Are there any advantages when you use it like this?

6th Jul 2020, 8:19 PM
Karak10
Karak10 - avatar
1 Answer
+ 1
From what I understand it takes the biggest size that can fit in the page, depending on the valuea of the viewBox the shape is formed, for example, if height and width have same size we have a square, so it makes a square and makes it as big as possible.
6th Jul 2020, 8:27 PM
Karak10
Karak10 - avatar