Favorites

HTML <svg> Tag

<svg>
HTML TagThis tag is supported by all modern browsers.
Updated 22nd November 2026

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.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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

<svg width="120" height="120" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="40" fill="#4361ee"/>
<text x="50" y="57" text-anchor="middle" font-size="20" fill="white">SVG</text>
</svg>
Open in editor

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.

This tag is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.