Chapter 17: SVG Fill

SVG Fill Attributes basically means all the ways you can control the color / pattern / gradient / transparency / rule that fills the inside of SVG shapes (rectangle, circle, ellipse, polygon, closed path, text, etc.).

The most important thing to remember right from the start:

  • stroke = border / outline
  • fill = inside color / pattern

Almost every closed shape (and even some open ones if you force it) uses fill.

1. The Main Fill Attribute – fill

This is the one you use 90% of the time.

XML

Possible values for fill:

Value type Example What it does
Named color red, blue, lime, purple Standard CSS color names (140+ available)
Hex #ff0000, #00f, #f0f8ff Most common in code
RGB rgb(255, 0, 0), rgb(0 255 0 / 0.5) Modern syntax allows alpha
HSL hsl(120, 100%, 50%), hsla(240,100%,50%,0.7) Great for themes & adjustments
Current color currentColor Uses the inherited color property (very useful)
none none Transparent – no fill at all
URL reference url(#myGradient), url(#pattern1) Points to gradient or pattern defined in <defs>

2. Quick Copy-Paste Playground (Try These One by One)

HTML

3. Fill-Rule – The Hidden Boss Attribute (fill-rule)

This decides which parts get filled when paths cross or overlap (very important for complex shapes, stars, letters with holes, etc.).

Two main values:

Value What it means Best for Example shape result
nonzero (default) Counts winding direction – odd crossings = fill, even = hole Most normal shapes Solid star without center hole
evenodd Fills only odd crossings – creates holes where paths overlap Shapes with intentional holes (donut, letters O, complex icons) Star with empty center, O with hole

Real example everyone should try:

XML

→ Top star = solid gold (nonzero default) → Bottom star = gold with white hole in middle (evenodd)

4. Fill-Opacity (Separate Control)

You can control transparency of fill only (stroke stays separate).

XML

→ Purple fill is 40% opaque, border full opaque

You can also use alpha in color: fill=”rgba(128,0,128,0.4)” or fill=”#80008066″

5. Fill with Gradients & Patterns (Most Beautiful Part)

Instead of solid color → fill=”url(#someId)”

Linear Gradient Example

XML

Radial Gradient (Shiny Ball Effect)

XML

Pattern Fill (Repeating Texture)

XML

→ Polka-dot fill!

6. Teacher’s Quick Summary Table (Exam/Interview Style)

Property / Attribute Controls what? Most common values Can be animated?
fill Inside color / gradient / pattern red, #ff0000, url(#grad), none Yes
fill-rule How overlapping areas are filled nonzero (default), evenodd No
fill-opacity Transparency of fill only 0–1, 0.5, 0.75 Yes
paint-order Order: fill / stroke / markers normal, stroke fill, markers stroke fill No

7. Final Tips from Your Teacher 😄

  • Default fill = black — always set it or you get surprise black shapes
  • Use currentColor when you want fill to follow text/icon color scheme
  • evenodd is your friend for icons with holes (Font Awesome, Material icons use it a lot)
  • For glass / overlay effect → low fill-opacity + backdrop-filter (CSS)
  • Practice: Take any icon from svgrepo.com → change fill, fill-rule, add gradient — see magic!

Understood SVG fill attributes fully now? Want to go deeper: animated fill change? Conic gradient? Mesh gradient (new)? Or full icon recoloring project? Just tell me — we keep building your SVG skills! 🚀

You may also like...

Leave a Reply

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