Description
The HTML element <svg>
is used to define SVG graphics in an HTML document.
The word SVG stands for Scalable Vector Graphics, which is an XML-based image format that is used to define two-dimensional vector-based graphics for the web.
The below table summarizes its usage.
Usage Details | |
Placement | It is displayed as an Inline element. |
Contents | It can contain SVG elements. |
Tags | Both the opening and closing tags are required. |
Versions | HTML 5 |
Syntax
Here is the basic syntax of the <svg>
element.
<svg>...</svg>
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example - HTML Element svg</title>
</head>
<body>
<h1>HTML SVG element to draw a rectangle</h1>
<svg width="500" height="350">
<rect x="100" y="100" width="300" height="150" fill="yellow" stroke="black" stroke-width="5" />
</svg>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <svg>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <svg> doesn't have any element-specific attributes. |
Global Attributes | Like all other HTML tags, the tag <svg> supports the HTML Global Attributes. |
Event Attributes | The tag <svg> also supports the HTML Event Attributes. |
Browser Compatibility
The tag <svg>
is supported in all modern browsers.
- Google Chrome 4+
- Internet Explorer or Edge 4+
- Firefox 4+
- Apple Safari 3.2+
- Opera 10.1+