How to use .svg files in a webpage?

The svg files are Scalable Vector Graphics. You can add it to a web page using the <img>, <iframe>, <object> or <embed> tag.

The .svg file is to be referenced in the src attribute of the <img> tag. Let’s see how to add it using the <img> tag.

You can try to run the following code to learn how to use .svg files in a web page. We have a smiley.svg file −

<!DOCTYPE html>
      <title>HTML SVG</title>

      <img src=
         id="demo" alt="smiley">
Swarali Sree
Swarali Sree

I love thought experiments.