You can display an SVG file within an HTML document, by specifying it as a background image in CSS. For example:
.element {
background-size: 100px 100px;
background: url(my_svg_file.svg);
height: 100px;
width: 100px;
}
If the dimensions specified in your SVG file are larger than the dimensions of your HTML element, it may be desirable to specify the background-size
property, to scale the SVG to fit within its element.
As with using SVG as an <img>
, it's worth noting some limitations with this approach: