HTML Canvas Reference
HTML Canvas Reference
The HTML <canvas> tag is used to draw graphics, on the fly, via scripting (usually JavaScript).
To learn more about <canvas>, please read our HTML Canvas tutorial.
Property Description
fillStyle Sets or returns the color, gradient, or pattern used to fill the drawing
strokeStyle Sets or returns the color, gradient, or pattern used for strokes
shadowOffsetX Sets or returns the horizontal distance of the shadow from the shape
shadowOffsetY Sets or returns the vertical distance of the shadow from the shape
MethodDescription
Line Styles
Property Description
lineCap Sets or returns the style of the end caps for a line
lineJoin Sets or returns the type of corner created, when two lines meet
Rectangles
MethodDescription
Paths
MethodDescription
moveTo() Moves the path to the specified point in the canvas, without creating a line
closePath() Creates a path from the current point back to the starting point
lineTo() Adds a new point and creates a line to that point from the last specified point in the canvas
clip() Clips a region of any shape and size from the original canvas
isPointInPath() Returns true if the specified point is in the current path, otherwise false
Transformations
MethodDescription
setTransform() Resets the current transform to the identity matrix. Then runs transform()
Text
Property Description
font Sets or returns the current font properties for text content
textBaseline Sets or returns the current text baseline used when drawing text
MethodDescription
measureText() Returns an object that contains the width of the specified text
Image Drawing
MethodDescription
Pixel Manipulation
Property Description
data Returns an object that contains image data of a specified ImageData object
MethodDescription
getImageData() Returns an ImageData object that copies the pixel data for the specified rectangle on a
canvas
putImageData() Puts the image data (from a specified ImageData object) back onto the canvas
Compositing
Property Description
globalAlpha Sets or returns the current alpha or transparency value of the drawing
globalCompositeOperation Sets or returns how a new image is drawn onto an existing image
Other
MethodDescription
createEvent()
getContext()
toDataURL()