<pattern>
Core element
Define a reusable repeating tile inside <defs> with a unique id.

SVG <pattern> tiles a small design to fill any shape. This tutorial covers defining patterns in <defs>, tile size with width/height, coordinates with patternUnits, rotation with patternTransform, applying paint with url(#id), five worked examples, and how patterns compare to gradients and solid fills.
Core element
Define a reusable repeating tile inside <defs> with a unique id.
width / height
Set how large each repeat unit is — smaller tiles mean denser repetition.
Coordinate space
userSpaceOnUse for fixed units or objectBoundingBox for relative sizing.
Apply paint
Use fill or stroke with url(#yourId) on any shape.
Rotate & scale
Rotate, scale, or skew the tile with patternTransform.
Dots, stripes & more
Patterns can contain circles, rects, paths, and even other SVG elements.
SVG patterns let you fill shapes with repeating textures — dots, stripes, grids, and custom motifs — all defined as vectors. They add visual interest to backgrounds, charts, maps, and UI elements without exporting raster images.
You define a <pattern> once (usually in <defs>), draw the tile content inside it, then reference it with url(#id) on fill or stroke.
Raster background images blur when scaled and add HTTP weight. SVG patterns stay crisp, stay tiny in markup, and can be shared across many shapes with one definition.
One pattern id can fill or stroke many shapes.
width and height control how often the motif repeats.
Dots, stripes, paths — anything SVG can draw works as a tile.
Same paint works for solid fills and patterned outlines.
In short: draw a small tile in <pattern>, then paint shapes with url(#id).
Basic form of an SVG pattern:
<svg width="300" height="120">
<defs>
<pattern id="dots" patternUnits="userSpaceOnUse" width="12" height="12">
<circle cx="6" cy="6" r="3" fill="#ef4444" />
</pattern>
</defs>
<rect x="20" y="30" width="260" height="60" rx="12" fill="url(#dots)" />
</svg> | Name | Type | Description |
|---|---|---|
<pattern> | Element | Defines a repeating tile; place inside <defs> with an id. |
width, height | Length / % | Size of one repeat unit (the tile). |
patternUnits | Keyword | userSpaceOnUse (absolute) or objectBoundingBox (0–1 relative). |
patternContentUnits | Keyword | Coordinate system for shapes inside the pattern tile. |
patternTransform | Transform list | Rotate, scale, or skew the pattern, e.g. rotate(45). |
x, y | Length / % | Offset of the pattern tile origin. |
| Tile content | SVG shapes | Any elements drawn inside <pattern> become the repeating motif. |
| Effect | Tile contents | Notes |
|---|---|---|
| Polka dots | <circle> centred in the tile | Classic background texture |
| Stripes | Two <rect> side by side | Vertical or horizontal bars |
| Diagonal | Any tile + patternTransform="rotate(45)" | Rotated repetition |
<!-- 1. Define -->
<defs>
<pattern id="stripes" patternUnits="userSpaceOnUse" width="20" height="20">
<rect width="10" height="20" fill="#3b82f6" />
<rect x="10" width="10" height="20" fill="#f8fafc" />
</pattern>
</defs>
<!-- 2. Apply -->
<rect fill="url(#stripes)" /> | Goal | Code |
|---|---|
| Define pattern | <pattern id="p" patternUnits="userSpaceOnUse" width="10" height="10">...</pattern> |
| Fill a shape | fill="url(#p)" |
| Stroke a shape | stroke="url(#p)" stroke-width="8" |
| Rotate tile | patternTransform="rotate(45)" |
| Fixed coordinates | patternUnits="userSpaceOnUse" |
| Scale tile | patternTransform="scale(0.5)" |
All paint SVG shapes — pick the paint that matches the look you want.
repeating tileTextures, grids, dots, and motifs
straight blendColours along a vector — UI bars & buttons
centre-outHighlights, glows, and orbs
one colourSimplest fill when no texture is needed
Reach for <pattern> when a shape needs a repeating texture rather than a smooth colour blend.
Dots, stripes, and grid fills for panels and hero sections.
Hatch fills to distinguish series or regions without extra colours.
Subtle motifs on cards, badges, and illustration backgrounds.
Dashed or textured outlines on paths and circles.
For directional colour ramps, use linear gradients instead.
Key benefit: one tile definition, infinite repetition — crisp textures at every scale.
Five starter snippets using <pattern>. Click View Output for a preview, or Try It Yourself to edit live.
Define a pattern tile, fill a shape, then try stripes and rotation.
Define a small dot tile and repeat it across a larger rounded rectangle.
<svg width="220" height="180" viewBox="0 0 220 180">
<defs>
<pattern id="dots" patternUnits="userSpaceOnUse" width="12" height="12">
<circle cx="6" cy="6" r="3" fill="#ef4444" />
</pattern>
</defs>
<rect x="10" y="10" width="200" height="160" rx="16" fill="url(#dots)" />
</svg> The pattern lives in <defs>. Each 12×12 tile contains one circle; fill="url(#dots)" tiles it across the rectangle.
Patterns can contain multiple SVG elements. Here two rectangles form a repeating stripe tile.
<svg width="220" height="180" viewBox="0 0 220 180">
<defs>
<pattern id="stripes" patternUnits="userSpaceOnUse" width="20" height="20">
<rect width="10" height="20" fill="#3b82f6" />
<rect x="10" width="10" height="20" fill="#f8fafc" />
</pattern>
</defs>
<rect x="10" y="10" width="200" height="160" rx="16" fill="url(#stripes)" stroke="#e2e8f0" />
</svg> The tile is 20×20: a blue half and a light half. SVG repeats the tile horizontally and vertically to cover the shape.
Rotation, circles, and patterned strokes.
Rotate the stripe tile 45° for diagonal hatching without redrawing the tile content.
<svg width="220" height="180" viewBox="0 0 220 180">
<defs>
<pattern id="diag" patternUnits="userSpaceOnUse" width="16" height="16"
patternTransform="rotate(45)">
<rect width="8" height="16" fill="#a855f7" />
<rect x="8" width="8" height="16" fill="#f3e8ff" />
</pattern>
</defs>
<rect x="10" y="10" width="200" height="160" rx="16" fill="url(#diag)" />
</svg> patternTransform="rotate(45)" rotates the entire tile before repetition — a quick way to get diagonal stripes from vertical bars.
Patterns work on any shape, not just rectangles. Here a dot tile fills a circle.
<svg width="240" height="200" viewBox="0 0 240 200">
<defs>
<pattern id="circleDots" patternUnits="userSpaceOnUse" width="10" height="10">
<circle cx="5" cy="5" r="2.5" fill="#22c55e" />
</pattern>
</defs>
<circle cx="120" cy="100" r="80" fill="url(#circleDots)" />
</svg> The browser tiles the pattern across the circle’s bounding box, then clips to the circle shape — same url(#id) syntax as a rectangle.
Apply a repeating pattern to a path’s stroke for a textured outline.
<svg width="260" height="160" viewBox="0 0 260 160">
<defs>
<pattern id="strokePat" patternUnits="userSpaceOnUse" width="8" height="8">
<rect width="4" height="8" fill="#f97316" />
<rect x="4" width="4" height="8" fill="#fdba74" />
</pattern>
</defs>
<rect x="30" y="30" width="200" height="100" rx="20" fill="none"
stroke="url(#strokePat)" stroke-width="12" />
</svg> stroke="url(#strokePat)" paints the outline with the repeating tile. Use fill="none" when you only want the patterned border.
Real-world places where SVG patterns show up every day.
Subtle dot or grid textures behind content panels.
Example: light polka dots on a hero card.
Distinguish data series when colour alone is not enough.
Example: diagonal stripes for a secondary bar series.
Fill geographic areas with repeating motifs.
Example: cross-hatch for water vs land zones.
Add depth to flat icons with fine-grain patterns.
Example: noise dots inside a badge shape.
Patterned strokes as decorative separators.
Example: dashed stripe line between sections.
Animated pattern shifts for skeleton screens.
Example: sliding stripe tile via CSS transform.
Pro Tip: keep pattern ids unique per inline SVG on a page — duplicate ids can make the wrong tile apply.
Why paint with SVG patterns instead of raster background images.
Stays sharp on retina screens without extra image assets.
One tile definition paints many shapes via url(#id).
One small tile covers shapes of any size automatically.
Textured outlines on paths, circles, and rectangles.
Rotate or scale tiles with patternTransform without redrawing.
Pro Tip: for UI backgrounds, keep tiles subtle — low-contrast dots or fine grids read better than bold stripes.
Follow these practices for clean, scalable SVG patterns.
Put patterns in <defs> (or earlier in the SVG) before url(#id).
Absolute tile units are easier to reason about than objectBoundingBox.
Names like dots, stripes, or gridPat are easier to maintain.
Rotate existing tiles instead of redrawing diagonal content.
Verify the tile looks good on rects, circles, and paths before shipping.
Pro Tip: smaller tile sizes (8–16 px) usually produce smoother-looking textures on large shapes.
Avoid these mistakes when your pattern refuses to show up.
fill="url(#missing)" paints nothing useful.
→ Match the id on <pattern> exactly.
Multiple SVGs on one page sharing the same id can collide.
→ Give each pattern a unique id per document.
Too-large tiles look sparse; too-small tiles can feel noisy.
→ Adjust width/height until repetition looks balanced.
objectBoundingBox uses 0–1 coordinates, which behave differently from pixels.
→ Stick to userSpaceOnUse until you need relative sizing.
Smooth colour blends need gradients, not repeating tiles.
→ Use linear gradients for directional colour ramps.
Pro Tip: if a fill is blank, check the id spelling, that tile content exists inside <pattern>, and that the pattern is defined in the same SVG document.
Patterns should live in <defs> so they can be reused across multiple shapes.
Place shapes inside <pattern> — circles, rects, paths, or any SVG elements that form one repeat unit.
width and height define the tile size. patternUnits="userSpaceOnUse" uses absolute coordinates.
Use fill="url(#id)" to fill shapes or stroke="url(#id)" to paint outlines. The tile repeats automatically.
SVG patterns make graphics feel richer and more tactile while staying crisp at any scale.
<defs> and reference them with url(#id).width/height set the tile dimensions that repeat across the shape.patternTransform rotates or scales the tile before repetition.fill and stroke on any shape.patternUnits="userSpaceOnUse" is the most predictable choice for beginners.Quick Takeaway: draw a tile in <pattern>, give it an id, paint with url(#id). Keep ids unique on the page.
SVG <pattern> is supported in all modern browsers — and has been for many years — as part of SVG 1.1 paint servers.
Use patterns in inline SVG or external .svg files. Tile fills, patternTransform, and url(#id) paints work consistently across Chrome, Firefox, Safari, Edge, and mobile browsers.
Bottom line: Safe for production sites. Prefer inline SVG or cached .svg assets; no polyfill is required for current browsers.
SVG patterns are reusable tile paint: define <pattern> with tile content and dimensions, then apply with fill or stroke via url(#id).
Practice the five examples above, then continue to SVG Linear Gradients when colour should blend smoothly in a direction.
Keep ids unique, start with userSpaceOnUse, and use patternTransform for rotation without redrawing tiles.
patternUnits="userSpaceOnUse" for predictable tile sizingpatternTransform for rotation or scalingdots, stripes, gridPat)objectBoundingBox uses 0–1 coordinatesPaint shapes with repeating vector tiles.
Reusable tile in defs
APIwidth + height
Repeatuser space vs bbox
Coordsfill or stroke
Applyrotate & scale tiles
RotateAn SVG <pattern> is reusable tile paint — define it once in <defs> with an id, then apply it with fill="url(#id)" or stroke="url(#id)". You can also animate patternTransform with CSS or SMIL for sliding or rotating texture effects.
Learn smooth directional colour blends for buttons, bars, and icons.
8 people found this page helpful