I think if I omit the viewBox
attribute from svg it is assumed to be viewBox="0 0 100 100"
. I tried two tests:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-triangle" width='100' height='100'>
<path d="M 50,5 95,97.5 5,97.5 z"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-triangle" width='100' height='100' viewBox="0 0 100 100">
<path d="M 50,5 95,97.5 5,97.5 z"/>
</svg>
As both the results are same I think my guess is correct. Please give some reference to explain What is default value of viewBox attribute if omitted from svg.
To remove the viewBox and get the equivalent transform, you can just surround the contents of the SVG with a group element ( <g> ). Then give that the equivalent transform. So for an equivalent transform, we have to combine a scale and a translate. To simulate your file we'll use this equivalent.
The viewBox attribute defines the position and dimension, in user space, of an SVG viewport. The value of the viewBox attribute is a list of four numbers: min-x , min-y , width and height .
viewbox is like a second set of virtual coordinates – all vectors inside the SVG will use the viewbox, while you can manipulate the actual height, width properties of the SVG without affecting the inside,. An SVG with a viewBox is so much easier to work with. I would never put an SVG together without one.
https://www.w3.org/TR/SVG2/coords.html#ViewBoxAttribute
The default value of an omitted viewbox is "As if not specified."
The problem here is a bit conceptual. So the equivalent viewbox to a non-specified viewbox is 0 0 width height
but an unspecified viewbox simply does not exist. A viewbox is equal to a transform and you often, if rendering this stuff, would make the equivalent transform to a viewbox and add that into your matrix. And unspecified viewbox applies no transformation at all. So this question becomes what is the default value of an unspecified transform
attribute.
It might help to think of the SVG object itself as an element within Euclidean space, just like the shapes within it. It would be possible for a circle
object (though not within the spec) to have a viewbox. This would mean it would have a sort of zoom into the coordinate system of the circle and make that zoomed view equal to the size of the circle. So everything that can have a width and height within the space could have a viewbox, and a few of them actually do like image objects and nested SVG objects. Without a viewbox everything is the size that it actually exists within the space. In the case of the SVG object itself this means the viewbox is equal to the view which is equivalent to viewing it at 0 0 width height
since that's the actual size of the object itself. But, really the effect of not having a viewbox is no-effect. Really a viewbox equal to 0 0 width height
will end up applying no scale or translate values when turned into a transform. But, that could have been achieved by simply omitting it.
If the width and height are omitted they are taken to be equal to 100%. Which is to say they take up 100% of the space within the physical box being used to view them. The viewport as opposed to the viewbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With