The svg element can be used to embed an SVG fragment inside the current document (for example, an HTML document). This SVG fragment has its own viewport and coordinate system.

Usage context

CategoriesContainer element, Structural element
Permitted contentAny number of the following elements, in any order:
Animation elements
Descriptive elements
Shape elements
Structural elements
Gradient elements
<a>, <altGlyphDef>, <clipPath>, <color-profile>, <cursor>, <filter>, <font>, <font-face>, <foreignObject>, <image>, <marker>, <mask>, <pattern>, <script>, <style>, <switch>, <text>, <view>

Example

Consider the following SVG image (representing the national flag of Italy):

<svg xmlns="http://www.w3.org/2000/svg" 
     width="150" height="100" viewBox="0 0 3 2">

  <rect width="1" height="2" x="0" fill="#008d46" />
  <rect width="1" height="2" x="1" fill="#ffffff" />
  <rect width="1" height="2" x="2" fill="#d2232c" />
</svg>

It could be included in an HTML5 document as follows:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>HTML/SVG Example</title>
</head>

<body>

  <svg xmlns="http://www.w3.org/2000/svg"
       width="150" height="100" viewBox="0 0 3 2">
    <rect width="1" height="2" x="0" fill="#008d46" />
    <rect width="1" height="2" x="1" fill="#ffffff" />
    <rect width="1" height="2" x="2" fill="#d2232c" />
  </svg>

</body>
</html>

Attributes

Global attributes

Specific attributes

DOM Interface

This element implements the SVGSVGElement interface.

Specifications

Specification Status Comment
Scalable Vector Graphics (SVG) 2
The definition of '<svg>' in that specification.
Candidate Recommendation  
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of '<svg>' in that specification.
Recommendation Initial definition

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support1 Yes1.5983
baseProfile Yes ? ? ? ? ?
contentScriptType No ? ? ? ? ?
contentStyleType No ? ? ? ? ?
height1 Yes1.5983
preserveAspectRatio1 Yes1.5983
version Yes ? ? ? ? ?
viewBox1 Yes1.5983
width1 Yes1.5983
x1 Yes1.5983
y1 Yes1.5983
zoomAndPan Yes ? ? ? ? ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support3 Yes Yes4 Yes3 ?
baseProfile Yes Yes ? ? ? ? ?
contentScriptType No No ? ? ? ? ?
contentStyleType No No ? ? ? ? ?
height3 Yes Yes4 Yes3 ?
preserveAspectRatio3 Yes Yes4 Yes3 ?
version Yes Yes ? ? ? ? ?
viewBox3 Yes Yes4 Yes3 ?
width3 Yes Yes4 Yes3 ?
x3 Yes Yes4 Yes3 ?
y3 Yes Yes4 Yes3 ?
zoomAndPan Yes Yes ? ? ? ? ?

Document Tags and Contributors

 Last updated by: fscholz,