On an <canvas>, four context properties control shadows: shadowColor, shadowBlur, shadowOffsetX, and shadowOffsetY. They affect later fills, strokes, and text until you change them.
A shadow is drawn only when shadowColor is not fully transparent and at least one of blur / offset X / offset Y is non-zero. Use soft blur with zero offset for a glow; use offsets for a classic drop shadow.
Baseline · Widely available.
Canvas shadow properties are stable Canvas 2D features across modern browsers since about July 2015.
Deprecated · Non-standard: setShadow().
Some WebKit/Blink engines still expose ctx.setShadow(). Prefer the four standard properties above — do not use setShadow in new code.
save() snapshots shadow settings (and other state).
Draw the orange rect with a drop shadow.
restore() clears the shadow props.
Blue rect has no shadow — it never inherited those settings.
Edge Cases & Pitfalls
Most “missing shadow” bugs are transparent color, zero blur/offset, or clipping at the canvas edge.
visible
Color + blur/offset required
Need a non-transparent shadowColor and at least one non-zero blur or offset. Otherwise nothing is drawn.
clip
Shadows can clip
Large blur or offset near the canvas edge gets cut off. Leave padding around shadowed shapes.
perf
Heavy blur costs
Very large shadowBlur values are slower, especially in animations. Prefer modest blur when redrawing often.
leak
Settings leak
Later draws inherit the shadow. Use save()/restore(), or reset color/blur/offsets after use.
Compatibility
Browser Support
Canvas shadow properties are part of the Canvas 2D API in every modern browser.
✓ Baseline · Widely available
Canvas shadows
Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support shadowColor, shadowBlur, and offsets. Internet Explorer 9+ also supports them.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+
Supported
shadowBlur / offsetsWidely supported
Bottom line: Safe for production drop shadows and soft glows on Canvas 2D everywhere modern browsers run.
Remember
Key Takeaways
Four props: color, blur, offsetX, offsetY.
Visible: opaque-enough color + blur or offset ≠ 0.
Glow vs drop: zero offset vs positive offsets.
Isolate:save() / restore().
One line: set shadow props → draw → restore.
UA style
Default CSS Settings
Shadows are a Canvas API concern. The <canvas> element still uses typical user-agent CSS:
default.css
canvas {
display: inline;
}
Set bitmap size with HTML width/height. CSS-only sizing scales the display and can soften shadowed edges.
Frequently Asked Questions
Set shadowColor to a non-transparent color, then set shadowBlur and/or shadowOffsetX / shadowOffsetY. Shadows apply to later fills, strokes, and text until you change or clear them.
shadowColor must be opaque enough to see, and at least one of shadowBlur, shadowOffsetX, or shadowOffsetY must be non-zero. Transparent color or all zeros means no shadow.
It is a blur level, not an exact pixel radius, and it is not affected by the current transform matrix. Larger numbers look softer.
Set shadowColor to transparent (or "transparent"), and/or set blur and offsets back to 0. Prefer save()/restore() so only one draw uses the shadow.
Yes. The same four properties affect fillText, strokeText, fill, and stroke operations.
No. setShadow() is a non-standard, deprecated WebKit/Blink helper. Use shadowColor, shadowBlur, shadowOffsetX, and shadowOffsetY instead.