Skip to content
Related Articles
Open in App
Not now

Related Articles

How to include SVG code inside HTML file ?

Improve Article
Save Article
  • Last Updated : 29 Sep, 2021
Improve Article
Save Article

Introduction: SVG stands for Scalable Vector Graphics. It 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 logo, 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 which 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.

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:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!