HTML Tags

HTML5 <svg> Tag

Topic: HTML5 Tags ReferencePrev|Next

Description

The <svg> element is used to embed SVG graphics in an HTML document.

The Scalable Vector Graphics (SVG) is an XML-based image format that is used to define two-dimensional vector based graphics for the web. See the tutorial on HTML5 SVG to learn more about it.

The following table summarizes the usages context and the version history of this tag.

Placement: Inline
Content: SVG elements
Start/End Tag: Start tag: required, End tag: required
Version: New in HTML5

Syntax

The basic syntax of the <svg> tag is given with:

HTML / XHTML: <svg> ... </svg>

The example below shows the <svg> tag in action.

<svg width="500" height="350">
    <rect x="100" y="100" width="300" height="150" fill="yellow" stroke="black" stroke-width="5" />
</svg>

The following example demonstrates how to draw a simple SVG smiley face.

<svg viewBox="0 0 200 200" width="400"  height="400">
    <circle cx="100" cy="100" fill="yellow" r="78" stroke="black" stroke-width="3" />
    <g>
        <circle cx="65" cy="82" r="12" />
        <circle cx="130" cy="82" r="12" />
    </g>
    <path d="M65 115 a1,0.8 0 0,0 65,0" fill="none" stroke="black" stroke-width="3" />
</svg>

Tag-Specific Attributes

The <svg> tag doesn't have any specific attribute.


Global Attributes

Like all other HTML tags, the <svg> tag supports the global attributes in HTML5.


Event Attributes

The <svg> tag also supports the event attributes in HTML5.


Browser Compatibility

The <svg> tag is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 4+
  • Google Chrome 4+
  • IE / Edge 9+
  • Apple Safari 3.2+
  • Opera 10.1+

Further Reading

See tutorial on: HTML5 SVG.

Related tags: <canvas>.

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties