Open In App

How to include SVG code inside HTML file ?

Last Updated : 14 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

SVG stands for Scalable Vector Graphics. It is an XML-based format used to describe vector graphics. SVG is widely supported in modern web browsers, including Google Chrome, Firefox, Opera, and others, which can render SVG images seamlessly. Designers frequently use the SVG format for creating illustrations, logos, and icons, as SVG images are pixel-perfect at any resolution, ensuring clarity and quality regardless of scaling.

Let’s see examples to understand How to Add the SVG Code.

Using the <svg> Tag

To include SVG graphics in an HTML document, you use the <svg> tag. This tag acts as a container for SVG graphics and is placed within the <body> section of the HTML file. The <svg> tag consists of both opening and closing tags, and it often includes attributes like width and height to define the size of the SVG image.

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:



Next Article

Similar Reads