CanvasRenderingContext2D: createConicGradient() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2023.

The CanvasRenderingContext2D.createConicGradient() method of the Canvas 2D API creates a gradient around a point with given coordinates.

This method returns a conic CanvasGradient. To be applied to a shape, the gradient must first be assigned to the fillStyle or strokeStyle properties.

Note: Gradient coordinates are global, i.e., relative to the current coordinate space. When applied to a shape, the coordinates are NOT relative to the shape's coordinates.

Syntax

js
createConicGradient(startAngle, x, y)

Parameters

startAngle

The angle at which to begin the gradient, in radians. The angle starts from a line going horizontally right from the center, and proceeds clockwise.

x

The x-axis coordinate of the center of the gradient.

y

The y-axis coordinate of the center of the gradient.

Return value

A conic CanvasGradient.

Examples

Filling a rectangle with a conic gradient

This example initializes a conic gradient using the createConicGradient() method. Five color stops between around the center coordinate are then created. Finally, the gradient is assigned to the canvas context, and is rendered to a filled rectangle.

HTML

html
<canvas id="canvas" width="240" height="240"></canvas>

JavaScript

js
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");

// Create a conic gradient
// The start angle is 0
// The center position is 100, 100
const gradient = ctx.createConicGradient(0, 100, 100);

// Add five color stops
gradient.addColorStop(0, "red");
gradient.addColorStop(0.25, "orange");
gradient.addColorStop(0.5, "yellow");
gradient.addColorStop(0.75, "green");
gradient.addColorStop(1, "blue");

// Set the fill style and draw a rectangle
ctx.fillStyle = gradient;
ctx.fillRect(20, 20, 200, 200);

Rectangle result

Specifications

Specification
HTML
# dom-context-2d-createconicgradient-dev

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
createConicGradient
Chrome – Full support
Chrome 99 (Release date: 2022-03-01)
footnote Full support
Edge – Full support
Edge 99 (Release date: 2022-03-03)
footnote Full support
Firefox – Partial support
Firefox 90 – 111 (Release date: 2021-07-13)
footnote Partial support
footnote Implements an older version of the specification. The gradient starts from a line going vertically up from the center, like the equivalent CSS function.
Firefox – Full support
Firefox 112 (Release date: 2023-04-11)
footnote Full support
Opera – Full support
Opera 85 (Release date: 2022-03-23)
footnote Full support
Safari – Partial support
Safari 15 – 16 (Release date: 2021-09-20)
footnote Partial support
footnote Implements an older version of the specification. The gradient starts from a line going vertically up from the center, like the equivalent CSS function.
Safari – Full support
Safari 16.1 (Release date: 2022-10-24)
footnote Full support
Chrome Android – Full support
Chrome Android 99 (Release date: 2022-03-01)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 90 – 111 (Release date: 2021-07-13)
footnote Partial support
footnote Implements an older version of the specification. The gradient starts from a line going vertically up from the center, like the equivalent CSS function.
Firefox for Android – Full support
Firefox for Android 112 (Release date: 2023-04-11)
footnote Full support
Opera Android – Full support
Opera Android 68 (Release date: 2022-03-30)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 15 – 16 (Release date: 2021-09-20)
footnote Partial support
footnote Implements an older version of the specification. The gradient starts from a line going vertically up from the center, like the equivalent CSS function.
Safari on iOS – Full support
Safari on iOS 16.1 (Release date: 2022-10-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 18 (Release date: 2022-08-08)
footnote Full support
WebView Android – Full support
WebView Android 99 (Release date: 2022-03-01)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 15 – 16 (Release date: 2021-09-20)
footnote Partial support
footnote Implements an older version of the specification. The gradient starts from a line going vertically up from the center, like the equivalent CSS function.
WebView on iOS – Full support
WebView on iOS 16.1 (Release date: 2022-10-24)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.

See also