Canvas States

You are Here:

Canvas State

Your browser does not support the canvas element.

In this example, the save() method to save the default state and restore() to restore it later, so that you are able to draw a rect with the default state later.


HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <canvas id="point" width="120" height="250"> Your browser does not support the canvas element. </canvas> <script> const canvas = document.getElementById('point'); const ctx = canvas.getContext('2d'); // Save the default state; ctx.fillStyle = '#339933'; ctx.fillRect(10, 10, 100, 100); // Restore the default state ctx.restore(); ctx.fillRect(10, 140, 100, 100); </script> </body> </html>


save()Saves the entire state of the canvas by pushing the current state onto a stack.
restore()Restores the most recently saved canvas state by popping the top entry in the drawing state stack.


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.

Share this Page

Meet the Author