Canvas Color & Effects

Beginner
8 min read
Updated: Nov 2026
4 topic guides
Appearance hub

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.

Beginner path.

Solid fills first → linear gradient → radial gradient → patterns → images.

Syntax

A linear fill, then the same idea as a radial fill:

JavaScript
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 topics

Color ramps along a line or between two circles — assign to fillStyle or strokeStyle.

TopicDescriptionTutorial
Linear GradientscreateLinearGradient and addColorStop along a line.Open
Radial GradientscreateRadialGradient between two circles.Open

Patterns & images

2 topics

Tile textures and draw or edit bitmap content on the surface.

TopicDescriptionTutorial
PatterncreatePattern for repeating image fills and strokes.Open
Manipulating ImagesdrawImage, 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.

0.50

Blue → amber mid stop → green. Assign the gradient to fillStyle, then fill.

Canvas

type="linear" mid="0.50"

How to Learn Color & Effects

A practical order for this hub:

  1. Finish shadows and save/restore from State & Styling.
  2. Build a two-stop linear gradient and fill a rectangle.
  3. Add a mid addColorStop and try the gradient on a stroke.
  4. Switch to a radial gradient for circles and soft spotlights.
  5. Tile a small image with createPattern.
  6. Draw photos with drawImage, then peek at pixel APIs.
  7. Continue to Transforms to move and scale painted content.

Frequently Asked Questions

Fills beyond solid colors: linear and radial gradients, repeating image patterns, and drawing or reading bitmap images on the canvas.
Start with linear gradients — the createGradient + addColorStop workflow is the same. Radial gradients reuse that pattern with two circles instead of a line.
createPattern(image, repetition) builds a fill or stroke style that tiles an image (or canvas/video). Use it for textures, stripes, and repeating backgrounds.
Yes. Assign the CanvasGradient to fillStyle or strokeStyle before you fill() or stroke().
drawImage paints an image onto the canvas. getImageData / putImageData read and write raw pixels for filters and effects — covered in Manipulating Images.
This page is the index for the Color & Effects sidebar section. Each topic page has full syntax, live demos, examples, and FAQs.

Start with Linear Gradients

Open the gradient guide — color stops, live preview, and examples.

Linear Gradients →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful