Canvas

Canvas Tutorials

Canvas Methods and Properties

Canvas

All Canvas Tutorials, Quizzes & Exercises

Canvas Tutorials
Canvas Intro
The HTML canvas element is used to draw graphics on a web page.
Drawing
All drawing on the HTML canvas must be done with JavaScript.
Coordinates
The HTML canvas is a two-dimensional grid. The upper-left corner of the canvas has the coordinates (0,0)
Linear Gradient
Gradients can be used to fill rectangles, circles, lines, text, etc. Shapes on the canvas are not limited to solid colors.
Radial Gradient
Gradients can be used to fill rectangles, circles, lines, text, etc. Shapes on the canvas are not limited to solid colors.
Text
To draw text on a canvas, the most important property and methods are font(), fillText(), strokeText()
Canvas Image
To draw an image on a canvas, we have to use drawImage() method.
Canvas Methods and Properties
canvas fillStyle Property in HTML
The fillStyle property sets or returns the color, gradient, or pattern used to fill the drawing.
canvas strokeStyle Property in HTML
The strokeStyle property sets or returns the color, gradient, or pattern used for strokes.
canvas shadowColor Property in HTML
The shadowColor property sets or returns the color to use for shadows.
canvas shadowBlur Property in HTML
The shadowBlur property sets or returns the blur level for shadows.
canvas shadowOffsetX Property in HTML
The shadowOffsetX property is used to sets or return the horizontal distance of the shadow from the shape.
canvas shadowOffsetY Property in HTML
The shadowOffsetY property is used to sets or returns the vertical distance of the shadow from the shape.
canvas createLinearGradient() Method in HTML
The createLinearGradient() method creates a linear gradient object. It is used to fill rectangles, circles, lines, etc.
Canvas createPattern() Method in HTML
The createPattern() method repeats specified elements in a specified direction. The element can be an image, video, or another canvas element.
canvas createRadialGradient() Method in HTML
The createRadialGradient() method creates a radial or circular gradient object. It can be used to fill rectangles, circles, lines, etc.
canvas addColorStop() Method in HTML
The addColorStop() method is used to specify color and position in a gradient object. It is used together with createLinearGradient() or createRadialGradient().
HTML canvas lineCap Property
The lineCap property sets or returns the style of the end caps for a line.
canvas stroke() Method in HTML
The stroke() method is used to draw the path that is defined by moveTo() and lineTo() methods. The default color is black.
canvas beginPath() Method in HTML
The beginPath() method begins a path, or resets the current path. It is used with lineTo(), arcTo(), moveTo(), quadricCurveTo(), bezierCurveTo(), arc() to create different styles of paths.
canvas moveTo() Method in HTML
The moveTo() method moves the path to the specified point in the canvas, without creating a line.
HTML canvas closePath() Method
The closePath() method creates a path from the current point back to the starting point. 
canvas lineTo() Method in HTML
The lineTo() method adds a new point and creates a line to that point from the last specified point in the canvas.
canvas clip() Method in HTML
The clip() method clips a region of any shape and size from the original canvas. When a region is clipped, all drawings will happen on that clipped region.
HTML canvas quadraticCurveTo() Method
The quadraticCurveTo() method is used to add a point to the current path by using the specified control points that represent a quadratic Bézier curve.
HTML canvas bezierCurveTo() Method
The bezierCurveTo() method is used to add a point to the current path by using the specified control points that represent a cubic Bézier curve.
canvas arc() Method in HTML
The arc() method is used to create an arc or curve.
HTML canvas arcTo() Method
The arcTo() method is used to create an arc or curve between two tangents on canvas.
canvas isPointInPath() Method in HTML
The isPointInPath() method is used to return true if the specified point is in the current path, otherwise false.
HTML canvas lineJoin Property
The lineJoin property is used to sets or returns the type of corner created when two lines met each other.
canvas lineWidth Property in HTML
The lineWidth property is used to sets or return the current line width, in pixels.
canvas miterLimit Property in HTML
The miterLimit property sets or returns the maximum miter length. It is the distance between the inner corner and the outer corner where two lines meet.
canvas rect() Method in HTML
The rect() method creates a rectangle. It is used in combination with the stroke() and fill() method to actually draw it on canvas.
HTML canvas fillRect() Method
The fillRect() method is used to draw a filled rectangle. The default color of the fill is black
canvas strokeRect() Method in HTML
The strokeRect() method is used to draw a rectangle. The default color is Black. We can change its color by strokeStyle() property.
HTML canvas clearRect() Method
The clearRect() method is used to clear the specified pixels within a given rectangle.
canvas fill() Method in HTML
The fill() method is used to fill the current drawing path. Its default value is black.
canvas scale() Method in HTML
The scale() method is used to scales the current drawing, bigger or smaller.
HTML canvas rotate() Method
The rotate() method is used to rotates the current drawing.
canvas translate() Method in HTML
The translate() method is used to remaps the (0,0) position on the canvas.
canvas transform() Method in HTML
The transform() method is used to replaces the current transformation matrix.
canvas setTransform() Method in HTML
The setTransform() method is used to resets the current transform to the identity matrix, and then runs transform() with the same arguments.
canvas font Property in HTML
The font property is used to sets or returns the current font properties for text content on the canvas.
canvas textAlign Property in HTML
The textAlign property is used to sets or returns the current alignment for text content, according to the anchor point.
canvas textBaseline Property in HTML
The textBaseline property is used to sets or returns the current text baseline used when drawing text.
canvas fillText() Method in HTML
The fillText() method is used to draws filled text on the canvas. Its default color is black.
canvas strokeText() Method in HTML
The strokeText() method is used to draw text without fill on the canvas. Its default color is black.
canvas measureText() Method in HTML
The measureText() method is used to returns an object that contains the width of the specified text, in pixels.
canvas drawImage() Method in HTML
The drawImage() method is used to draw an image, canvas onto the canvas.
canvas ImageData width Property in HTML
The width returns the width of an ImageData object, in pixels. Its syntax is:- imgData.width;
canvas ImageData height Property in HTML
The height returns the height of an ImageData object, in pixels. Its syntax is:- imgData.height;
canvas ImageData data Property in HTML
The data property is used to return an object that contains image data of the specified ImageData object.
canvas createImageData() Method in HTML
The createImageData() method is used to create a new, blank ImageData object. Its pixel values are transparent black by default.
canvas getImageData() Method in HTML
The getImageData() method is used to return an ImageData object that copies the pixel data for the specified rectangle on a canvas.
canvas putImageData() Method in HTML
The putImageData() method is used to put the image data back onto the canvas from a specified ImageData object.
canvas globalAlpha Property in HTML
The globalAlpha property is used to sets or returns the current alpha or transparency value of the drawing.
canvas globalCompositeOperation Property in HTML
The globalCompositeOperation property is used to define how a new (source) image is drawn onto an existing (destination) image.