Chapter 25: SVG Patterns

SVG Patterns are one of the most fun and powerful ways to fill shapes (rectangles, circles, paths, text, polygons, etc.) with a repeating tile / texture / wallpaper made of SVG elements — instead of a solid color or gradient.

Think of it like:

  • You create a small “tile” (a little drawing: dots, stripes, hearts, stars, checkerboard, bricks, etc.)
  • You tell SVG: “Repeat this tile forever in all directions to fill the shape”
  • Result: seamless repeating pattern, completely vector (zoom forever, still sharp)

This is how you get:

  • Polka-dot backgrounds
  • Diagonal stripes
  • Checkerboard / grid
  • Brick wall / honeycomb
  • Custom fabric / paper textures
  • Fun decorative icons or text fills

1. Basic Structure – The Two Main Tags

You need two elements:

  1. <pattern> → defines the repeating tile (lives inside <defs>)
  2. fill=”url(#myPattern)” → applies it to any shape

Basic skeleton:

XML

2. Key Attributes of <pattern>

Attribute What it means Default Most common values Notes
id Unique name to reference “dots”, “stripes”, “checker” Must have!
width Width of one tile (repeat unit) 1 10, 20, 50, 100 In user units or %
height Height of one tile 1 same as width usually Usually square, but can be rectangle
patternUnits Coordinate system for width/height objectBoundingBox userSpaceOnUse (most used), objectBoundingBox userSpaceOnUse = absolute pixels
patternContentUnits Coordinate system for content inside pattern userSpaceOnUse userSpaceOnUse, objectBoundingBox Usually leave default
x / y Offset of first tile 0 5, -10 Shift pattern start
patternTransform Rotate / scale / skew the whole pattern none rotate(45), scale(2) Very powerful

3. Your First SVG Pattern – Simple Polka Dots (Copy-Paste Now!)

HTML

Result: Big rectangle filled with repeating black polka dots every 40×40 units.

4. More Real & Fun Pattern Examples (Try These!)

A. Diagonal Stripes (Very Popular)

XML

→ Red-cyan stripes (change colors to your brand)

B. Checkerboard / Grid

XML

→ Classic black-white checkerboard

C. Small Hearts Pattern (Romantic / Decorative)

XML

→ Tiny repeating hearts (adjust scale/transform)

D. Rotated Diagonal Pattern (45° Stripes)

XML

→ Use patternTransform to rotate the entire tile pattern

E. Pattern on Stroke (Repeating Border)

XML

→ Thick dotted border around circle

5. Teacher’s Quick Tips (Hyderabad Student Style 😄)

  • Use patternUnits=”userSpaceOnUse” → easiest, size in absolute units (pixels)
  • Make tile size small (10–60) → smooth repeat without huge file
  • Add patternTransform=”rotate(45) scale(1.2)” → endless design possibilities
  • Common mistake: Forget width/height on <pattern> → pattern invisible or huge
  • Pro trick: Put complex SVG (group of shapes, text, image) inside pattern → crazy textures
  • Performance: Very lightweight — much better than repeating background-image in CSS for vectors
  • Combine with fill-opacity=”0.7″ or filters → semi-transparent patterns

Understood SVG Patterns fully now? They’re the secret behind most creative, repeating, textured fills you see in modern web design and illustrations.

Tell me what you want next:

  • Animated pattern (moving stripes / marching ants)?
  • Pattern with image inside (<image> tag)?
  • Complex pattern (honeycomb + text)?
  • Pattern on text fill?
  • Or compare patterns vs gradients vs images?

Just say — we can build any pattern style together right now! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *