HTML <svg>
Tag
The <svg>
tag is used to define a graphics element on a web page. SVG stands for Scalable Vector Graphics, which is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation.
SVG images can be created inline within an HTML document or as standalone files. They can be scaled to any size without losing quality, making them ideal for responsive web design.
Attributes and Usage
Attribute | Description |
---|---|
width |
Sets the width of the SVG image. |
height |
Sets the height of the SVG image. |
viewBox |
Specifies the position and dimensions of the SVG viewport. |
xmlns |
Defines the XML namespace for the SVG element (xmlns="http://www.w3.org/2000/svg"). |
fill |
Sets the fill color of the SVG shape. |
stroke |
Sets the stroke color of the SVG shape. |
Example
Here is an example of an SVG rectangle:
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="80" height="80" fill="blue" stroke="black" />
</svg>
This code creates a blue rectangle with a black stroke, positioned at (10,10) with a width and height of 80 pixels.
SVG can be used to create various shapes, lines, text, and more. It also supports animations and interactivity, making it a versatile tool for web developers.