Canvas globalCompositeOperation Property

Canvas globalCompositeOperation Property

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

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
typeA 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

Reminder

Hi Developers, we almost covered 93% of Canvas Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in Canvas.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Meet the Author