Open In App

SVG <svg> Element

SVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas.

SVG graphics are supported by the <svg> element in HTML. SVG graphics feature a container in which we can create a variety of shapes such as boxes, pathways, text, graphic images, and circles.



Syntax:

<svg width="x" height="y"> shape_tags... </svg>

Attributes: 



Example 1: Making a circle with an outline of green and fill colored black.




<!DOCTYPE html>
<html lang="en">
<body>
    <svg viewBox="0 0 300 100" stroke="green" 
        fill="dark green">
        <circle cx="50" cy="50" r="40" />
    </svg>
</body>
</html>

cx represents the width of the circle and cy represents the height of the circle, and r represents the radius of the circle.

        <circle cx="50" cy="50" r="40"/>

Output:

 

Example 2: Making a rectangle with an outline of dark green and fill colored light green.




<!DOCTYPE html>
<html lang="en">
<h1>GeeksForGeeks</h1>
<body>
    <svg width="400" height="100">
        <rect width="400" height="100" 
            style="fill:rgb(20, 204, 20);
                stroke-width:10;stroke:rgb(14, 180, 89)"/>
    </svg>
</body>
</html>

Output:

 

List of browsers Supported:


Article Tags :