|
|
Donner 0.5.1
Embeddable browser-grade SVG2 engine
|
Defines a paint server containing a repeated pattern, which is tiled to fill the area.
A <pattern> is a tileable paint server: you draw a small graphic once inside the <pattern> element, then fill any shape with fill="url(#id)" and SVG repeats (tiles) that graphic across the filled region. Unlike gradients, which vary color smoothly, a pattern repeats an arbitrary sub-drawing — stripes, dots, crosshatches, custom textures — as many times as needed to cover the shape.
Patterns are typically declared inside a "<defs>" block. The width and height control the size of each tile (in either object-bounding-box or user-space units depending on patternUnits), and the viewBox lets the pattern contents author their own coordinate system. For smooth color transitions, use "<linearGradient>" or "<radialGradient>" instead.
To reference it with a fill:
The patternUnits attribute controls how the pattern's tile rectangle (x, y, width, height) is interpreted. The two modes produce very different results when the same pattern is applied to shapes of different sizes.
patternTransform applies an extra transformation to the tile grid — you can rotate, skew, or scale the tiling without affecting the filled shape itself. Common uses include diagonal stripes (rotate 45°) and textures drawn "on an angle".
| Attribute | Default | Description |
|---|---|---|
| viewBox | (none) | A list of four numbers (min-x, min-y, width, height) that specifies a rectangle in userspace mapped to the pattern viewport. |
| preserveAspectRatio | xMidYMid meet | How to scale the viewport to fit the content. Only applies if viewBox is specified. |
| x | 0 | Top-left X of the tile rectangle. Interpretation depends on patternUnits. |
| y | 0 | Top-left Y of the tile rectangle. Interpretation depends on patternUnits. |
| width | 0 | Width of one tile. Interpretation depends on patternUnits. |
| height | 0 | Height of one tile. Interpretation depends on patternUnits. |
| patternUnits | objectBoundingBox | Coordinate system for x, y, width, height: objectBoundingBox (fraction of the filled shape's bounds) or userSpaceOnUse (absolute user-space units). |
| patternContentUnits | userSpaceOnUse | Coordinate system for the pattern contents. Has no effect when viewBox is specified. |
| patternTransform | identity | Additional transform applied to the tile grid (rotate, skew, scale) without affecting the filled shape. |
| href | (none) | Reference to another pattern element to use as a template. |