On an <canvas>, a path is a reusable outline you build in memory. Add points with moveTo / lineTo, arc, or bezierCurveTo, then paint with stroke() or fill().
Call beginPath() before each new shape so strokes do not share one path. Use closePath() to seal an outline. For reusable shapes, store a Path2D object.
Baseline · Widely available.
Core path methods (beginPath, closePath, stroke, fill) are stable since about July 2015. Path2D is widely available since about August 2016.
Build, then paint.
Path methods only update the current path. Nothing shows until stroke() or fill() runs.
Create new Path2D() and add the same path commands.
translate moves where the path is drawn (path coords stay local).
fill(tri) then stroke(tri) reuse one definition.
Ideal for icons you draw many times without rebuilding points.
Edge Cases & Pitfalls
Most path bugs come from sharing one path across strokes or forgetting to paint.
begin
Always beginPath() for a new shape
Skipping it merges shapes into one path. Colors and unexpected connectors follow.
paint
Paths are invisible until painted
Finish with stroke() and/or fill(). Building alone changes nothing on screen.
fill
Open paths fill poorly
For solid fills, closePath() (or end at the start point) so the interior is well defined.
holes
Holes need evenodd (or composition)
Default nonzero fills overlapping areas. Use fill("evenodd") or composition modes.
clip
clip() is related but different
clip() turns the current path into a mask for later draws. It does not stroke or fill by itself.
Compatibility
Browser Support
Path building and painting are core Canvas 2D. Path2D is also widely supported in modern browsers.
✓ Baseline · Widely available
Paths
beginPath/closePath/stroke/fill: widely available since about July 2015. Path2D: widely available since about August 2016. Chrome, Firefox, Safari, Edge, and Opera support both.
97%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+ paths / no Path2D
Partial
beginPath / Path2DWidely supported
Bottom line: Use core path methods everywhere. Prefer Path2D when you can assume modern browsers (IE has no Path2D).
Separate shapes: new beginPath() for each independent stroke.
Holes:fill("evenodd") with nested sub-paths.
Reuse:Path2D stores a shape for later fill/stroke.
One line: a canvas path is built, then painted — never drawn by path methods alone.
UA style
Default CSS Settings
Paths are a Canvas API concern. The <canvas> element still uses typical user-agent CSS:
default.css
canvas {
display: inline;
}
Set bitmap size with HTML width/height. CSS-only sizing scales the bitmap and can blur path strokes.
Frequently Asked Questions
A path is a list of points and curves you build with methods like moveTo, lineTo, and arc. Nothing appears until you stroke() or fill() that path.
beginPath() clears the previous path list so the next stroke or fill only paints the new shape. Without it, shapes can share one path and unexpected lines appear.
It connects the current point back to the start of the sub-path with a straight line. Useful before fill() so the outline is sealed.
stroke() paints the outline. fill() paints the interior. You can call both: fill first, then stroke, for a filled shape with a border.
Path2D lets you store a reusable path object and draw it later with ctx.stroke(path) or ctx.fill(path). Handy when the same shape is used more than once.
fill("evenodd") uses the even-odd rule so overlapping sub-paths can create holes. The default nonzero fills the whole enclosed area.