HTML SVG

2.19.2024
Copy

HTML SVG

By Tony 2.19.2024
Favorite Share Report


For a website to be interesting, you not only need to have text and images, you also need graphics and icons. While using images is a way to add icons to your site, HTML SVG (Scalable Vector Graphics) is a better option. It's very flexible, meaning it maintains its resolution when scaling and it's responsive, and it also has many other benefits like animations, small file size, and customization.

Note: There isn't a file called "icon.svg" as in the example, so it shows the alternative text.

In the above example, we introduced 4 new tags: <svg>, <rect>, <circle>, and <text>, along with an <img> tag, and several new attributes.

Note that this is just a very little portion of SVG introduced. Except for <rect>, <circle>, and <text>, there are still tons of other tags and attributes that can be used in SVG and are more complex. To summarize, there are two ways to put SVG into your web page. One, by putting SVG code directly in your HTML document with different tags, or two, by using an <img> tag to display an external SVG file. If you already have an SVG downloaded, use the <img> tag, otherwise, use inline SVG, as you can have better flexibility and control over the codes.