What is the HTML < svg > element?
The <svg> element in
What is SVG?
- SVG is an abbreviation for Scalable Vector Graphics.
- You can use SVG to generate vector-based graphics for the web.
- SVG defines the graphics in XML format describing 2D-based vector graphics.
- Every attribute or element in SVG files can be animated, as well as recommended by W3C standards.
- SVG also supports DOM and XSL, which are W3C standards.
Syntax
<svg width="x" height="y"> shape_tags... </svg>
Shapes Element
The <svg> element can draw multiple shapes with different attributes. Here are some elements to draw different shapes like circles, ellipses, polygons etc.
Useful Elements for Shapes
Tag | Attribute | Description |
<rect /> | width and height | Generates multiple shapes like squares, rectangles, etc. |
<polygon /> | points | Generates polygons like stars, pentagons, etc. |
<ellipse /> | cx, cy, rx, and ry | Draws ellipse-like shapes. |
<circle /> | cx, cy, and r | Draws circles of every shape. |
Demo Code
Using the <svg> element in lines 7, 12, and 17 generates a circle, rectangle, and star, respectively. The objects or SVG images are of different widths and heights, with a black border and filled red color.