Chapter 48: Canvas Shadows

Canvas Shadows in the clearest, most patient, step-by-step way possible.

Imagine I’m sitting right next to you with my screen open. We’re going to build every concept together — slowly, with tiny complete runnable examples you can copy-paste immediately. No skipping steps, no magic, just plain English explanations, visual thinking, common beginner traps, and repeated patterns until shadows feel completely natural and easy to control.

Canvas Shadows – From Zero to Confident

1. The single most important sentence about shadows in Canvas

Shadows in Canvas are painted automatically whenever you draw any filled or stroked shape — but only if you first set the shadow properties.

Canvas has a built-in shadow engine that works on every fill(), stroke(), fillRect(), strokeRect(), fillText(), strokeText(), arc(), etc. You don’t create a separate “shadow object”. You just tell the painter:

“From now on, every shape I draw should have a soft black shadow offset a little down and right.”

And the painter will draw that shadow under every filled/stroked shape — until you turn the shadow off or change its settings.

2. The four shadow properties you must set (all live in the context)

Property What it controls Common values Default value Very useful?
shadowColor Color of the shadow ‘#000’, ‘rgba(0,0,0,0.4)’, ‘#333’ transparent black ★★★★★
shadowBlur How soft/blurry the shadow is 0 (sharp), 4–12 (soft), 20+ (very soft) 0 ★★★★★
shadowOffsetX How far right (positive) or left (negative) 4, 8, -3 0 ★★★★★
shadowOffsetY How far down (positive) or up (negative) 4, 6, -2 0 ★★★★★

Golden rule (memorize this):

Shadows are only drawn when all four properties are set and shadowBlur > 0.

If any one is missing or zero, no shadow appears.

3. Minimal complete shadow example (copy → run)

HTML

What you should see & remember forever:

  • Green rectangle and blue circle both have soft black shadows
  • Shadows are automatically drawn under every filled/stroked shape
  • Shadows follow the shape exactly (even curves, text, images)
  • Shadows are drawn before the shape itself (so shape sits on top)

4. Example 2 – Different shadow styles (copy-paste & play)

HTML

Key lessons from this example:

  • shadowBlur = 0 → hard/flat shadow
  • Colored shadows → very modern look (purple, blue, etc.)
  • Glow effect → set offset to 0 or negative + large blur + light color
  • Inner glow trick → draw larger blurred light shape → then smaller solid shape on top

6. Your three tiny practice tasks (10–15 min each)

Task 1 – Simple shadow button Draw a rounded rectangle (use roundRect or manual path) Fill it with blue Add soft black shadow offset down-right

Task 2 – Glowing orb Draw a white circle Add blue radial gradient fill Add large soft white shadow around it (glow effect)

Task 3 – Floating cards Draw three small rectangles at different positions Give each a different colored shadow (red, green, purple)

Paste any of them here when you finish — I’ll review it like we’re pair-programming together.

Which part still feels a little slippery?

  • Why shadows appear automatically on every shape?
  • Difference between shadowBlur = 0 vs 10 vs 30?
  • How to make colored shadows vs black ones?
  • Creating glow/outer glow effect?
  • Inner glow trick?
  • Something else?

Tell me — we’ll stay on shadows until you feel super confident adding realistic depth to any Canvas drawing.

You’re doing really well — shadows are one of the things that instantly make Canvas graphics look polished and professional! 🚀

You may also like...

Leave a Reply

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