HTML <svg> Tag
The <svg> tag embeds scalable vector graphics directly in HTML. SVG shapes, paths and text stay sharp at any size and can be styled with CSS.
Description
The <svg> element embeds an SVG (Scalable Vector Graphics) image directly in an HTML document. It is the root element of the SVG language, and everything inside it, such as <circle>, <rect>, <path> and <text>, is parsed as SVG rather than HTML. Inline SVG graphics stay sharp at any size and can be styled with CSS and changed with JavaScript like other elements.
The viewBox attribute defines the internal coordinate system, while width and height (or CSS) set the displayed size; with a viewBox the graphic scales to fit. Common uses are icons (which can inherit the text color through fill="currentColor"), logos, charts and illustrations. For purely decorative graphics add aria-hidden="true"; for meaningful ones give them an accessible name with a <title> child or aria-label.
Properties
- Permitted Parents
- Any element that accepts phrasing content
- Content
- SVG elements (shapes, text, gradients and so on)
- Start/End Tags
- Start tag: required, End tag: required
Example
Attributes
- viewBox
- Defines the position and size of the SVG viewport in user units, as four numbers: min-x, min-y, width and height.
- width
-
The displayed width of the graphic. Default value:
auto(100% when used inline without a size). - height
- The displayed height of the graphic.
- preserveAspectRatio
-
How the graphic is scaled and aligned when the aspect ratio of the viewBox differs from that of the viewport. Default value:
xMidYMid meet. - xmlns
-
The SVG namespace,
http://www.w3.org/2000/svg. Required in standalone SVG files but optional for inline SVG in HTML.
Global Attributes
The <svg> tag also supports the Global Attributes in HTML5
Event Attributes
The <svg> tag also supports the Event Attributes in HTML5
Browser Support
The following information will show you the current browser support for the HTML <svg> tag. Hover over a browser icon to see the version that first introduced support for this HTML tag.
Desktop





Tablets & Mobile





