Last updated
SVG Pattern Element
The SVG <pattern> element defines a repeating tile that can be used
as a fill or stroke for other SVG elements. The pattern is defined once in <defs>
and referenced by ID. This is far more efficient than duplicating shapes — the browser
renders the tile once and tiles it across the fill area.
Pattern Units
| Attribute | Value | Effect |
|---|---|---|
| patternUnits | userSpaceOnUse | Pattern size in SVG user units (absolute) |
| patternUnits | objectBoundingBox | Pattern size relative to the filled element (0–1) |
| patternContentUnits | userSpaceOnUse | Pattern content in SVG user units (default) |
| patternContentUnits | objectBoundingBox | Pattern content relative to filled element |
Checkerboard Pattern Example
SVG
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern id="checker" x="0" y="0" width="20" height="20"
patternUnits="userSpaceOnUse">
<rect x="0" y="0" width="10" height="10" fill="#3498DB"/>
<rect x="10" y="10" width="10" height="10" fill="#3498DB"/>
<rect x="10" y="0" width="10" height="10" fill="#ECF0F1"/>
<rect x="0" y="10" width="10" height="10" fill="#ECF0F1"/>
</pattern>
<pattern id="dots" x="0" y="0" width="20" height="20"
patternUnits="userSpaceOnUse">
<circle cx="10" cy="10" r="3" fill="#E74C3C"/>
</pattern>
</defs>
<rect width="200" height="200" fill="url(#checker)"/>
</svg>