Embedding external SVG files in HTML
suggest changeYou can use the <img> or <object> elements to embed external SVG files. Setting the height and width is optional but is highly recommended.
Using the image element
<img src="attention.svg" width="50" height="50" alt="">
Using <img> does not allow you to style the SVG using CSS or manipulate it using JavaScript.
Using the object element
<object type="image/svg+xml" data="attention.svg" width="50" height="50"></object>
Unlike <img>, <object> embeds the SVG as a document and therefore it can be manipulated using JavaScript and CSS, subject to the same-origin policy.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents