Open In App

How to include SVG code inside HTML file ?

Improve
Improve
Like Article
Like
Save
Share
Report

Introduction: SVG stands for Scalable Vector Graphics. It is written in XML based format that is used to describe vector graphics. It is widely supported in browsers like Google Chrome, Firefox, Opera, etc. and many of them have the tendency to render SVG images. Designers also use SVG format for making the illustrations like logos, icons, etc. as they are pixel-perfect at any resolution.

In this article, we will insert a sample SVG code in the HTML file that will help you to include any SVG code that you want in your own HTML file.

<svg> Tag: In order to include SVG code, we have to use <svg> tag in the HTML code. It is a container that is used for SVG graphics. It is written inside the <body> section of the HTML file. It has both opening and closing tags. We also use width and height attributes with the <svg> tag

Now let’s see an example to understand it better.

Example: In this example, we will use SVG code in the HTML file.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>Include SVG Code</title>
</head>
 
<body>
    <center>
        <h2>Welcome To GFG</h2>
        <!-- SVG tag starts from here-->
        <svg width="600"
             height="150">
            <rect width="600"
                  height="150"
                  fill="green"
                  stroke="black"
                  stroke-width="6" />
        </svg>
        <!-- SVG tag ends here-->
    </center>
</body>
 
</html>


Output:


Last Updated : 29 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads