Canvas Color & Effects

Definition
Color & effects covers fills beyond solid colors: linear and radial gradients, tiled patterns, and drawing or editing images on the bitmap.
After shadows from State & Styling, open Linear Gradients and Radial Gradients, then Pattern and Manipulating Images.
Solid fills first → linear gradient → radial gradient → patterns → images.
Syntax
A linear fill, then the same idea as a radial fill:
const canvas = document.getElementById("demo");
const ctx = canvas.getContext("2d");
// Linear gradient
const lg = ctx.createLinearGradient(40, 40, 280, 40);
lg.addColorStop(0, "#2563eb");
lg.addColorStop(1, "#16a34a");
ctx.fillStyle = lg;
ctx.fillRect(40, 40, 240, 70);
// Radial gradient
const rg = ctx.createRadialGradient(160, 160, 10, 160, 160, 70);
rg.addColorStop(0, "#fbbf24");
rg.addColorStop(1, "#b45309");
ctx.fillStyle = rg;
ctx.beginPath();
ctx.arc(160, 160, 70, 0, Math.PI * 2);
ctx.fill(); Topics
Guides in the Color & Effects section (4 tutorials).
Gradients
2 topicsColor ramps along a line or between two circles — assign to fillStyle or strokeStyle.
| Topic | Description | Tutorial |
|---|---|---|
Linear Gradients | createLinearGradient and addColorStop along a line. | Open |
Radial Gradients | createRadialGradient between two circles. | Open |
Patterns & images
2 topicsTile textures and draw or edit bitmap content on the surface.
| Topic | Description | Tutorial |
|---|---|---|
Pattern | createPattern for repeating image fills and strokes. | Open |
Manipulating Images | drawImage, sizing, and pixel-level edits. | Open |
Live Preview
Switch linear vs radial and move the mid color stop — the same addColorStop idea as the topic pages.
How to Learn Color & Effects
A practical order for this hub:
- Finish shadows and save/restore from State & Styling.
- Build a two-stop linear gradient and fill a rectangle.
- Add a mid
addColorStopand try the gradient on a stroke. - Switch to a radial gradient for circles and soft spotlights.
- Tile a small image with
createPattern. - Draw photos with
drawImage, then peek at pixel APIs. - Continue to Transforms to move and scale painted content.
Frequently Asked Questions
Start with Linear Gradients
Open the gradient guide — color stops, live preview, and examples.
8 people found this page helpful
