htmlsvg

Resizing SVG in HTML?


I have an SVG file inside HTML, and one of the things I've heard about the format is that it doesn't get all pixelated when you zoom in on it.

I know with a JPEG or whatever I could have it stored as a 50 by 50 icon, then actually display it as a (rather pixelated) 100 by 100 thumbnail (or 10 by 10), by manually setting the height and width in the image_src tag.

However, SVG files seem to be used with object/embed tags, and changing the height or width of THOSE just results in more space being allocated for the picture.

Is there any way to specify that you want an SVG image displayed smaller or larger than it actually is stored in the file system?


Solution

  • Open your .svg file with a text editor (it's just XML), and look for something like this at the top:

    <svg ... width="50px" height="50px"...
    

    Erase width and height attributes; the defaults are 100%, so it should stretch to whatever the container allows it.