Embedding external SVG files in HTML

suggest change

You 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents