SVG presentation attributes let you style an element — its fill, stroke, font, opacity, and transform — directly in markup. Each is shorthand for a CSS property of the same name, but with the lowest priority in the cascade. This is a searchable offline reference.
How it works
Each attribute lists four facts that decide how it behaves:
- Value type — a
paint(color orurl(#id)), alength/number, atokenfrom an enumerated set, or astring. - Default — the value applied when the attribute is absent.
- CSS equivalent — almost all presentation attributes are also CSS properties. Setting it in CSS lets you theme, hover, and override; the attribute is a low-specificity fallback.
- Applies to — paint attributes apply to shapes and text; font/text attributes apply to text content elements.
Because presentation attributes sit below every CSS rule in the cascade, a stylesheet always wins. Use the attribute for static inline styling and CSS when you need theming or interaction.
The most commonly confused attributes
fill versus stroke. fill sets the interior color of a shape; stroke sets the outline color. Both accept a paint value: a color, none, currentColor, or a url(#id) reference to a gradient or pattern definition. A circle with fill="none" stroke="black" shows only the outline ring, not a solid disc.
stroke-width. This is the width of the stroke line in user units, which may be scaled by transforms. A stroke-width="2" on a shape inside a transform="scale(3)" renders at 6 user units visually. Set vector-effect="non-scaling-stroke" if you want the stroke to stay a fixed visual width regardless of transforms.
stroke-dasharray and stroke-dashoffset. stroke-dasharray defines the dash-gap pattern as alternating lengths: 4 2 means 4 units of dash then 2 units of gap. stroke-dashoffset shifts where in the pattern the stroke starts, which is the mechanism behind CSS line-drawing animations — starting with an offset equal to the path length and animating to zero makes the line appear to draw itself.
opacity versus fill-opacity and stroke-opacity. opacity applies to the entire element including both fill and stroke as a composited unit. fill-opacity and stroke-opacity are independent: a shape can have a solid stroke and a semi-transparent fill. Note that opacity creates a stacking context, which can affect how the element composites with layers behind it.
transform. The transform attribute on SVG elements takes the same functions as CSS transforms (translate, rotate, scale, matrix) but uses SVG’s own coordinate system and is specified slightly differently (no deg suffix on angles in the attribute form).
Example
<circle cx="50" cy="50" r="40"
fill="none" stroke="teal" stroke-width="6"
stroke-dasharray="10 4" stroke-linecap="round" />
stroke-dasharray="10 4" draws a 10-unit dash then a 4-unit gap, repeating; the
same effect in CSS is stroke-dasharray: 10 4.
Notes
- Geometry attributes (
x,cx,r,d,points) are not presentation attributes — they must stay in markup and have no CSS equivalent (SVG 2 adds some as CSS, but support is uneven). fillandstrokeaccept a paint: a color,none,currentColor, or aurl(#id)reference to a gradient or pattern.- Presentation attributes inherit: a
fillon a<g>group applies to all child elements unless overridden. - This reference covers the common presentation attributes, not the entire SVG 2 specification.