Canvas globalCompositeOperation Property

Last Updated:

Canvas globalCompositeOperation Property

ctx.globalCompositeOperation canvas property sets the type of compositing operation to apply when drawing new shapes.

Your browser does not support the canvas element.

This example uses the globalCompositeOperation property to draw two rectangles that hue themselves where they overlap.

Help Tips: Learn how to draw a canvas rectange.

Exampe

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <canvas id="point" width="160" height="160"> Your browser does not support the canvas element. </canvas> <script> var canvas = document.getElementById('point'); var ctx = canvas.getContext('2d'); ctx.globalCompositeOperation = 'hue'; ctx.fillStyle = 'blue'; ctx.fillRect(10, 10, 100, 100); ctx.fillStyle = 'red'; ctx.fillRect(50, 50, 100, 100); </script> </body> </html>

Syntax

ctx.globalCompositeOperation = type;

Attributes Value

ValueExplanation
type A String specifies which of the compositing or blending mode operations to use. The following are the list of possible values.
  • source-over
  • source-in
  • source-out
  • source-atop
  • destination-over
  • destination-in
  • destination-out
  • destination-atop
  • lighter
  • copy
  • xor
  • multiply
  • screen
  • overlay
  • darken
  • lighten
  • color-dodge
  • color-burn
  • hard-light
  • soft-light
  • difference
  • exclusion
  • hue
  • saturation
  • color
  • luminosity

Share this Page

Meet the Author