In HTML image element can be created without dimensions specified. It will have intrinsic width and height:
<img src="me.jpg" alt="">
However, in SVG image without dimension attributes will have 0×0 size, to prevent this width
and height
must be specified (as in this example):
<image xlink:href="me.jpg" width="64" height="64" />
Can SVG image be forced to take it's original width and height (without adding corresponding attributes, of course)? I'm curios about inline SVG inside HTML, if it matters.
The SVG 1.1 specification requires the width
and height
attributes for the <image> element. Most browsers today implement that, so the answer is not yet. Leaving the attributes off means a default value of 0
is used, which has the effect of making the image invisible.
However, autosizing of images is being added to SVG2, see https://svgwg.org/svg2-draft/embedded.html#ImageElement.
SVG 2 Requirement: Support auto-sized images.
Resolution: We will allow auto-sized images in SVG 2.
This hopefully means that you'll be able to do what you want in a not too distant future.
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