Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doesn't SVG support auto width and height for images?

Tags:

image

svg

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.

like image 608
Pavlo Avatar asked Apr 18 '13 10:04

Pavlo


1 Answers

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.

like image 179
Erik Dahlström Avatar answered Oct 11 '22 10:10

Erik Dahlström