This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.
The Path2D
interface of the Canvas 2D API is used to declare a path that can then be used on a CanvasRenderingContext2D
object. The path methods of the CanvasRenderingContext2D
interface are also present on this interface, which gives you the convenience of being able to retain and replay your path whenever desired.
Constructors
Path2D()
Path2D
constructor. Creates a newPath2D
object.
Methods
Path2D.addPath()
- Adds a path to the current path.
Path2D.closePath()
- Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.
Path2D.moveTo()
- Moves the starting point of a new sub-path to the (
x, y
) coordinates. Path2D.lineTo()
- Connects the last point in the subpath to the (
x, y
) coordinates with a straight line. Path2D.bezierCurveTo()
- Adds a cubic Bézier curve to the path. It requires three points. The first two points are control points and the third one is the end point. The starting point is the last point in the current path, which can be changed using
moveTo()
before creating the Bézier curve. Path2D.quadraticCurveTo()
- Adds a quadratic Bézier curve to the current path.
Path2D.arc()
- Adds an arc to the path which is centered at (
x, y
) position with radius 'r
starting atstartAngle
and ending atendAngle
going in the given direction byanticlockwise
(defaulting to clockwise). Path2D.arcTo()
- Adds a circular arc to the path with the given control points and radius, connected to the previous point by a straight line.
Path2D.ellipse()
- Adds an elliptical arc to the path which is centered at (
x, y
) position with the radiiradiusX
andradiusY
starting atstartAngle
and ending atendAngle
going in the given direction byanticlockwise
(defaulting to clockwise). Path2D.rect()
- Creates a path for a rectangle at ' position (
x, y
) with a size that is determined bywidth
andheight
.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living StandardThe definition of 'Path2D' in that specification. | Living Standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Chrome
Full support Yes |
Edge
Full support ≤18 |
Firefox
Full support 31 |
IE
No support No |
Opera
Full support Yes |
Safari
Full support 10 |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 31 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Chrome
Full support Yes |
Edge Full support ≤18 Full support ≤18 Notes' The constructor for |
Firefox
Full support 31 |
IE
No support No |
Opera
Full support Yes |
Safari
Full support 10 |
WebView Android
No support No |
Chrome Android
Full support 42 |
Firefox Android
Full support 31 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 4.0 | |
Chrome
Full support Yes |
Edge
Full support ≤79 |
Firefox
Full support 34 |
IE
No support No |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 34 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
- See implementation notes.'
- See implementation notes.
See also
Path2D by Mozilla Contributors is licensed under CC-BY-SA 2.5.