← Back to Index

SVG Elements & Attributes Reference

A comprehensive reference of all SVG elements and their key attributes. Organised by category.

Categories

Container Elements

<svg> Container

The root container. Establishes a new viewport and coordinate system. Can be nested.

AttributeDescription
width, heightViewport dimensions. CSS units or unitless (px).
viewBox"min-x min-y width height" - defines the user coordinate system.
preserveAspectRatioHow viewBox maps to viewport when aspect ratios differ. Default: xMidYMid meet.
xmlnsNamespace: http://www.w3.org/2000/svg. Required for standalone SVG files; optional when inline in HTML5.
x, yPosition when nested inside another SVG.
Example:
<svg width="200" height="150" viewBox="0 0 200 150">
  <circle cx="100" cy="75" r="50" fill="gold"/>
</svg>

<g> Container

Groups child elements. Applies shared transforms, styles, or event handlers. Does NOT create a new viewport.

AttributeDescription
transformTransformation applied to all children.
opacityGroup-level opacity (composites children as a unit before applying).
Example:
<g transform="translate(50, 30)" fill="#61afef">
  <rect x="0" y="0" width="40" height="30"/>
  <rect x="50" y="0" width="40" height="30"/>
</g>

<defs> Container

Defines reusable elements that are not rendered directly. Children are referenced via url(#id) or xlink:href/href.

Example:
<defs>
  <linearGradient id="sky">
    <stop offset="0%" stop-color="#87ceeb"/>
    <stop offset="100%" stop-color="#1e90ff"/>
  </linearGradient>
</defs>
<rect fill="url(#sky)" width="200" height="100"/>

<symbol> Container

Like <defs> content but with its own viewBox and preserveAspectRatio. Instantiated via <use>. Ideal for icon systems.

AttributeDescription
viewBoxInternal coordinate system for the symbol.
preserveAspectRatioAspect ratio handling when used at different sizes.
Example:
<symbol id="icon-star" viewBox="0 0 24 24">
  <polygon points="12,2 15,9 22,9 16,14 18,21 12,17 6,21 8,14 2,9 9,9"/>
</symbol>
<use href="#icon-star" width="48" height="48"/>

<use> Container

Instantiates a copy of another element (referenced by href). Creates a shadow DOM-like boundary that limits CSS styling from outside.

AttributeDescription
hrefReference to the element to clone: #id or file.svg#id.
x, yPosition offset for the cloned content.
width, heightOverride dimensions (only effective on <symbol> or <svg> targets).
Example:
<defs><circle id="dot" r="5"/></defs>
<use href="#dot" x="30" y="30" fill="red"/>
<use href="#dot" x="70" y="30" fill="blue"/>

<switch> Container

Renders the first child whose requiredFeatures, requiredExtensions, or systemLanguage evaluates to true. Used for internationalisation or feature detection.

Example:
<switch>
  <text systemLanguage="fr">Bonjour</text>
  <text systemLanguage="en">Hello</text>
  <text>Hi</text>
</switch>

Basic Shapes

<rect> Shape

Rectangle. Supports rounded corners.

AttributeDescription
x, yTop-left corner position. Default: 0.
width, heightDimensions. Required.
rx, ryCorner radii. If only one is specified, the other mirrors it. Max clamped to half the dimension.
Example:
<rect x="10" y="10" width="120" height="80" rx="8"
      fill="#e5c07b" stroke="#b8993f" stroke-width="2"/>

<circle> Shape

Circle defined by centre point and radius.

AttributeDescription
cx, cyCentre coordinates. Default: 0.
rRadius. Required. Negative values are invalid.
Example:
<circle cx="80" cy="80" r="50"
        fill="#e06c75" stroke="#b04950" stroke-width="2"/>

<ellipse> Shape

Ellipse - a circle with independent x and y radii.

AttributeDescription
cx, cyCentre coordinates.
rx, ryHorizontal and vertical radii.
Example:
<ellipse cx="100" cy="60" rx="80" ry="40"
         fill="#98c379" opacity="0.8"/>

<line> Shape

Straight line between two points. Must have a stroke to be visible (no fill).

AttributeDescription
x1, y1Start point.
x2, y2End point.
Example:
<line x1="10" y1="10" x2="190" y2="90"
      stroke="#c678dd" stroke-width="3" stroke-linecap="round"/>

<polyline> Shape

Connected series of straight line segments. Open shape (not automatically closed).

AttributeDescription
pointsSpace or comma-separated list of x,y pairs: "0,0 50,25 100,0".
Example:
<polyline points="20,80 60,20 100,60 140,10 180,50"
          fill="none" stroke="#61afef" stroke-width="2"/>

<polygon> Shape

Like <polyline> but automatically closes the shape (last point connects to first).

AttributeDescription
pointsSame format as polyline.
Example:
<polygon points="100,10 150,80 50,80"
         fill="#56b6c2" stroke="#3d8f99" stroke-width="2"/>

Paths

<path> Shape

The most powerful shape element. Can describe any 2D shape using a mini-language of commands in the d attribute.

AttributeDescription
dPath data string - a sequence of commands (see below).
pathLengthDeclares the "author's expected" total length. Affects stroke-dasharray and stroke-dashoffset calculations.

Path Commands

CommandNameParameters
M / mMove Tox y
L / lLine Tox y
H / hHorizontal Linex
V / vVertical Liney
C / cCubic Bézierx1 y1 x2 y2 x y (two control points + endpoint)
S / sSmooth Cubicx2 y2 x y (first control point reflected from previous)
Q / qQuadratic Bézierx1 y1 x y (one control point + endpoint)
T / tSmooth Quadraticx y (control point reflected from previous)
A / aArcrx ry x-rotation large-arc-flag sweep-flag x y
Z / zClose Path(none)

Uppercase = absolute coordinates. Lowercase = relative to current point.

Example:
<path d="M 10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80"
      fill="none" stroke="#c678dd" stroke-width="3"/>

Text

<text> Text

Renders text. Supports all font-related presentation attributes.

AttributeDescription
x, yPosition of the text anchor point (baseline-left by default). Can be a list for per-glyph positioning.
dx, dyRelative offsets. Can also be a list for per-glyph adjustment.
rotateRotation per glyph (list of degrees).
textLengthDesired total text length - browser adjusts spacing/glyphs to fit.
lengthAdjustspacing or spacingAndGlyphs.
Example:
<text x="20" y="40" font-size="18" fill="#333">Hello SVG</text>

<tspan> Text

Inline text span within <text>. Allows position/style changes mid-text (like <span> in HTML).

Accepts the same positioning attributes as <text>: x, y, dx, dy, rotate.

Example:
<text x="10" y="30">
  Normal <tspan fill="red" font-weight="bold">Bold Red</tspan> text
</text>

<textPath> Text

Renders text along the outline of a <path> element.

AttributeDescription
hrefReference to the path: #pathId.
startOffsetDistance along the path where text begins (length or %).
methodalign (default) or stretch.
spacingauto or exact.
Example:
<defs><path id="curve" d="M 10 80 Q 95 10 180 80"/></defs>
<text><textPath href="#curve">Text on a curve</textPath></text>

Paint Servers (Gradients & Patterns)

<linearGradient> Paint

Defines a linear colour gradient. Referenced as fill="url(#id)" or stroke="url(#id)".

AttributeDescription
x1, y1, x2, y2Start and end points of the gradient vector. Default: horizontal (0,0)→(1,0).
gradientUnitsobjectBoundingBox (default, 0–1 range) or userSpaceOnUse (absolute coords).
gradientTransformTransform applied to the gradient coordinate system.
spreadMethodpad (default), reflect, or repeat.
hrefInherit stops from another gradient.
Example:
<linearGradient id="sunset" x1="0" y1="0" x2="0" y2="1">
  <stop offset="0%" stop-color="#ff6b6b"/>
  <stop offset="100%" stop-color="#feca57"/>
</linearGradient>
<rect fill="url(#sunset)" width="200" height="100"/>

<radialGradient> Paint

Defines a radial (circular/elliptical) colour gradient.

AttributeDescription
cx, cyCentre of the end circle.
rRadius of the end circle.
fx, fyFocal point (centre of the start circle). Defaults to cx, cy.
frRadius of the focal (start) circle. Default: 0. (SVG 2)
gradientUnitsSame as linearGradient.
spreadMethodSame as linearGradient.
Example:
<radialGradient id="sphere" cx="50%" cy="50%" r="50%" fx="30%" fy="30%">
  <stop offset="0%" stop-color="white"/>
  <stop offset="100%" stop-color="#333"/>
</radialGradient>
<circle cx="80" cy="80" r="60" fill="url(#sphere)"/>

<stop> Paint

Defines a colour stop within a gradient.

AttributeDescription
offsetPosition along the gradient: 0–1 or 0%–100%.
stop-colorThe colour at this stop.
stop-opacityOpacity at this stop (0–1).
Example:
<stop offset="50%" stop-color="#e06c75" stop-opacity="0.8"/>

<pattern> Paint

Defines a repeating tile pattern used as a fill or stroke paint.

AttributeDescription
x, yPosition of the pattern tile origin.
width, heightSize of one tile.
patternUnitsobjectBoundingBox (default) or userSpaceOnUse.
patternContentUnitsCoordinate system for pattern contents.
patternTransformTransform on the pattern tile.
viewBoxInternal coordinate system for pattern contents.
Example:
<pattern id="dots" width="20" height="20" patternUnits="userSpaceOnUse">
  <circle cx="10" cy="10" r="3" fill="#61afef"/>
</pattern>
<rect fill="url(#dots)" width="200" height="100"/>

Clipping & Masking

<clipPath> Clipping

Defines a clipping region. Anything outside the clip path geometry is invisible. Binary: fully visible or fully hidden.

AttributeDescription
clipPathUnitsuserSpaceOnUse (default) or objectBoundingBox.

Applied via: clip-path="url(#id)"

Example:
<clipPath id="circle-clip">
  <circle cx="100" cy="75" r="60"/>
</clipPath>
<image href="photo.jpg" width="200" height="150" clip-path="url(#circle-clip)"/>

<mask> Masking

Defines a luminance or alpha mask. Unlike clipPath, supports soft edges and gradual transparency.

AttributeDescription
x, y, width, heightThe mask application area. Default: -10% to 120% of the target bounding box.
maskUnitsUnits for x/y/width/height: objectBoundingBox (default) or userSpaceOnUse.
maskContentUnitsUnits for mask content: userSpaceOnUse (default) or objectBoundingBox.

Applied via: mask="url(#id)"

Example:
<mask id="fade">
  <rect width="200" height="100" fill="url(#leftToRight)"/>
</mask>
<rect fill="teal" width="200" height="100" mask="url(#fade)"/>

Filter Effects

<filter> Filter

Container for filter primitives. Applied via filter="url(#id)".

AttributeDescription
x, y, width, heightFilter region. Default: -10% to 120%.
filterUnitsUnits for the filter region.
primitiveUnitsUnits for primitive coordinates within the filter.
Example:
<filter id="blur">
  <feGaussianBlur stdDeviation="3"/>
</filter>
<circle cx="80" cy="80" r="40" fill="tomato" filter="url(#blur)"/>

Filter Primitives

Each primitive takes in, in2 (input buffers) and produces a result (named output buffer). Common inputs: SourceGraphic, SourceAlpha, BackgroundImage, or a named result.

ElementPurposeKey Attributes
<feBlend>Blend two inputsmode: normal, multiply, screen, darken, lighten, overlay, etc.
<feColorMatrix>Colour space transformstype: matrix, saturate, hueRotate, luminanceToAlpha. values.
<feComponentTransfer>Per-channel transfer functionsContains <feFuncR>, <feFuncG>, <feFuncB>, <feFuncA>.
<feComposite>Porter-Duff compositingoperator: over, in, out, atop, xor, arithmetic. k1k4 for arithmetic.
<feConvolveMatrix>Convolution (sharpen, emboss, edge detect)kernelMatrix, order, divisor, bias, edgeMode.
<feDiffuseLighting>Diffuse lighting simulationsurfaceScale, diffuseConstant. Contains a light source element.
<feDisplacementMap>Pixel displacement using another imagescale, xChannelSelector, yChannelSelector.
<feDropShadow>Drop shadow (shorthand)dx, dy, stdDeviation, flood-color, flood-opacity.
<feFlood>Fill the filter region with a solid colourflood-color, flood-opacity.
<feGaussianBlur>Gaussian blurstdDeviation (one value = uniform, two = x/y). edgeMode.
<feImage>Fetch an external image or SVG fragment as filter inputhref, preserveAspectRatio.
<feMerge>Layer multiple inputs on top of each otherContains <feMergeNode> children with in attributes.
<feMorphology>Erode or dilate shapesoperator: erode, dilate. radius.
<feOffset>Offset the input imagedx, dy.
<feSpecularLighting>Specular (glossy) lightingsurfaceScale, specularConstant, specularExponent.
<feTile>Tile the input to fill the filter region(uses standard in/result)
<feTurbulence>Generate Perlin noise or fractal turbulencetype: turbulence, fractalNoise. baseFrequency, numOctaves, seed, stitchTiles.

Light Source Elements (inside feDiffuseLighting / feSpecularLighting)

ElementDescription
<feDistantLight>Directional light. Attrs: azimuth, elevation.
<fePointLight>Point light source. Attrs: x, y, z.
<feSpotLight>Spotlight. Attrs: x, y, z, pointsAtX/Y/Z, specularExponent, limitingConeAngle.
Example:
<filter id="shadow">
  <feDropShadow dx="3" dy="3" stdDeviation="2" flood-color="#000" flood-opacity="0.4"/>
</filter>
<rect x="20" y="20" width="100" height="60" fill="#61afef" filter="url(#shadow)"/>

Animation (SMIL)

SMIL stands for Synchronized Multimedia Integration Language. It's a W3C specification for describing multimedia presentations. SVG adopted a subset of SMIL for declarative, self-contained animation - no CSS or JavaScript required.

<animate> Animation

Animates a single attribute over time. The workhorse of SMIL animation.

AttributeDescription
attributeNameThe attribute to animate (e.g., cx, fill, opacity).
fromStart value.
toEnd value.
byRelative change (alternative to to).
valuesSemicolon-separated keyframe values (overrides from/to).
durDuration: 2s, 500ms, or indefinite.
beginWhen to start: time offset, event (click), syncbase (anim1.end), or indefinite.
endWhen to stop (same syntax as begin).
repeatCountNumber of repetitions or indefinite.
repeatDurTotal repeat duration.
fillfreeze (hold last value) or remove (revert to original). NOT the paint fill.
calcModeInterpolation: linear (default), discrete, paced, spline.
keyTimesSemicolon-separated time positions (0–1) for each values entry.
keySplinesCubic bezier control points for spline calcMode.
additivereplace (default) or sum (add to base value).
accumulatenone (default) or sum (each repeat builds on previous).
Example:
<circle cx="50" cy="50" r="20" fill="tomato">
  <animate attributeName="cx" from="50" to="150" dur="2s" repeatCount="indefinite"/>
</circle>

<animateTransform> Animation

Animates the transform attribute specifically. Required because transform values aren't simple scalars.

AttributeDescription
typeTransform type: translate, rotate, scale, skewX, skewY.
from, to, by, valuesValues appropriate to the type (e.g., "0 50 50" for rotate = angle cx cy).
additivesum allows composing multiple transform animations.

All timing attributes from <animate> apply.

Example:
<rect x="40" y="40" width="20" height="20" fill="#e5c07b">
  <animateTransform attributeName="transform" type="rotate"
    from="0 50 50" to="360 50 50" dur="3s" repeatCount="indefinite"/>
</rect>

<animateMotion> Animation

Moves an element along a path.

AttributeDescription
pathThe motion path (same syntax as <path d="...">).
rotateauto (orient to path tangent), auto-reverse, or a fixed angle.
keyPointsFine-grained control over position along path at each keyTime.

Can also contain an <mpath> child to reference an external path element.

Example:
<circle r="6" fill="#c678dd">
  <animateMotion path="M 20 50 Q 100 0 180 50" dur="2s" repeatCount="indefinite" rotate="auto"/>
</circle>

<mpath> Animation

Child of <animateMotion>. References a <path> element to use as the motion path.

AttributeDescription
hrefReference to the path element: #pathId.
Example:
<path id="track" d="M 10 80 Q 95 10 180 80" fill="none"/>
<circle r="5" fill="orange">
  <animateMotion dur="3s" repeatCount="indefinite"><mpath href="#track"/></animateMotion>
</circle>

<set> Animation

Sets an attribute to a fixed value for a duration. No interpolation - instant state change. Useful for visibility toggles, colour swaps on events, etc.

AttributeDescription
attributeNameAttribute to set.
toThe value to set.
begin, dur, end, fillStandard timing attributes.
Example:
<rect x="30" y="30" width="60" height="60" fill="blue">
  <set attributeName="fill" to="red" begin="click" dur="1s"/>
</rect>

Descriptive & Metadata

<title> Descriptive

Accessible name for the parent element. Shown as tooltip on hover in most browsers. Important for accessibility.

Example:
<circle cx="50" cy="50" r="30" fill="gold">
  <title>Golden coin</title>
</circle>

<desc> Descriptive

Longer accessible description. Not displayed visually but available to assistive technologies.

Example:
<svg role="img" aria-labelledby="chart-title chart-desc">
  <title id="chart-title">Sales chart</title>
  <desc id="chart-desc">Bar chart showing monthly sales from Jan to Jun.</desc>
</svg>

<metadata> Descriptive

Container for metadata (e.g., RDF, Dublin Core). Not rendered.

Example:
<metadata>
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description rdf:about="" dc:title="My Graphic"/>
  </rdf:RDF>
</metadata>

Linking & References

<a> Linking

Hyperlink wrapper for SVG content. Works like HTML <a>.

AttributeDescription
hrefLink target URL.
targetWhere to open: _self, _blank, etc.
Example:
<a href="https://example.com" target="_blank">
  <text x="10" y="30" fill="blue">Click me</text>
</a>

Markers

<marker> Marker

Defines a graphic drawn at vertices of <path>, <line>, <polyline>, or <polygon>. Think arrowheads, dots, or custom vertex decorations.

AttributeDescription
markerWidth, markerHeightSize of the marker viewport.
refX, refYThe point in the marker that aligns with the vertex.
orientauto (follow path tangent), auto-start-reverse, or a fixed angle.
markerUnitsstrokeWidth (default, scales with stroke) or userSpaceOnUse.
viewBoxInternal coordinate system.
preserveAspectRatioAspect ratio handling.

Applied via: marker-start, marker-mid, marker-end properties.

Example:
<marker id="arrow" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">
  <polygon points="0 0, 10 3.5, 0 7" fill="#333"/>
</marker>
<line x1="20" y1="50" x2="160" y2="50" stroke="#333" stroke-width="2" marker-end="url(#arrow)"/>

Images & Foreign Content

<image> Image

Embeds a raster image (PNG, JPEG, etc.) or another SVG file.

AttributeDescription
hrefImage URL.
x, yPosition.
width, heightRendered dimensions.
preserveAspectRatioHow to fit the image within the given dimensions.
Example:
<image href="photo.png" x="10" y="10" width="180" height="120"
       preserveAspectRatio="xMidYMid meet"/>

<foreignObject> Container

Embeds non-SVG content (typically HTML/XHTML) within an SVG. Extremely useful for rich text, form elements, or complex layouts inside SVG.

AttributeDescription
x, yPosition.
width, heightDimensions of the foreign content area.
Example:
<foreignObject x="20" y="20" width="160" height="80">
  <div xmlns="http://www.w3.org/1999/xhtml" style="font-size:14px;">
    <p>HTML content inside SVG</p>
  </div>
</foreignObject>

Presentation Attributes (CSS / SVG Overlap)

These are attributes that can also be set via CSS. They act as the lowest-priority style declaration (below user-agent stylesheet). CSS properties with the same name override them.

Priority order: Inline style="" > CSS rules (by specificity) > Presentation attributes

Attribute / CSS PropertyApplies ToDescription
fillShapes, textInterior paint: colour, gradient url(), pattern url(), none.
fill-opacityShapes, textOpacity of the fill paint (0–1).
fill-ruleShapesnonzero (default) or evenodd. Determines inside/outside for complex paths.
strokeShapes, textOutline paint.
stroke-widthShapes, textStroke thickness.
stroke-linecapShapesbutt (default), round, square.
stroke-linejoinShapesmiter (default), round, bevel.
stroke-dasharrayShapesDash pattern: "5 3", "10 5 2 5", etc.
stroke-dashoffsetShapesOffset into the dash pattern. Animating this creates "drawing" effects.
stroke-opacityShapes, textStroke paint opacity.
stroke-miterlimitShapesLimit on miter join extension. Default: 4.
opacityAllElement-level opacity (composites element then applies).
transformAll2D/3D transform. SVG values: translate(), rotate(), scale(), skewX(), skewY(), matrix().
transform-originAllOrigin for transforms. In SVG, defaults to 0 0 (not 50% 50% like CSS on HTML elements!).
visibilityAllvisible, hidden, collapse. Hidden elements still occupy space and receive events.
displayAllinline (default), none. none removes from rendering tree entirely.
clip-pathAllReference to a <clipPath>.
maskAllReference to a <mask>.
filterAllReference to a <filter>.
colorAllInherited current colour. Used via fill="currentColor".
font-familyTextFont family (same as CSS).
font-sizeTextFont size.
font-weightTextFont weight.
font-styleTextFont style (italic, oblique).
text-anchorTextstart (default), middle, end. SVG equivalent of text-align.
dominant-baselineTextVertical text alignment baseline.
text-decorationTextUnderline, overline, line-through.
letter-spacingTextSpace between characters.
word-spacingTextSpace between words.
pointer-eventsAllControls hit-testing: visiblePainted, visible, painted, fill, stroke, all, none.
cursorAllCursor style on hover.
overflow<svg>, <symbol>, <pattern>, <marker>visible (SVG default for outermost), hidden (default for inner SVG). Controls whether content outside viewport is clipped.

Key Differences: SVG Presentation Attributes vs CSS

BehaviourHTML + CSSSVG
Default transform-origin50% 50% (centre of element)0 0 (top-left of SVG viewport)
Box modelYes (margin, padding, border)No. SVG elements have no margin/padding/border.
fill / strokeNot applicable to HTMLPrimary paint mechanism for shapes.
backgroundYesNot applicable to SVG elements (use fill or underlying <rect>).
width/height via CSSSizes the elementOn <svg>: sizes viewport. On shapes: depends - <rect> respects CSS width/height in SVG 2; most shapes use geometry attributes.
Percentage valuesRelative to parent/containerRelative to viewBox dimensions (not parent element).

Global Attributes

Available on all SVG elements:

AttributeDescription
idUnique identifier. Used for referencing (url(#id), href="#id").
classCSS class(es). Space-separated.
styleInline CSS declarations.
tabindexTab order for keyboard navigation.
langLanguage of text content.
data-*Custom data attributes (same as HTML).
aria-*ARIA accessibility attributes.
roleARIA role.

Event Attributes

SVG elements support all standard DOM event handler attributes:

CategoryAttributes
Mouseonclick, onmousedown, onmouseup, onmouseover, onmouseout, onmousemove
Focusonfocusin, onfocusout
Keyboardonkeydown, onkeyup
SVG-specificonload, onunload, onabort, onerror, onresize, onscroll
Animationonbegin, onend, onrepeat

Notes

← Back to Index