We can already do linear gradients and radial gradients with CSS quite easily, and now there’s a 3rd type of gradient that will be defined in the spec. Conic gradients are similar to radial gradients, except that the color stops are on the outer edge of the circle that gets created.
For example, here’s a radial gradient and a conic gradient that have the same color stops:
And here’s the markup:
Conic gradients can have multiple color stops:
Each color can specify it’s stop position using units such as degrees, turns or percentages:
Notice how a second position value for a color stop specifies the transition.
The color stops can jump to the next color immediately by eliminating the transition between two stops:
You can specify the starting angle using the from keyword:
Furthermore, you can use the at keyword to specify the center of the transition:
Unfortunately I can’t show an example of using at at this moment because at the time of this writing there’s a bug in the polyfill that would make all the other examples crash when viewed in a browser that relies on the polyfill.
For smooth transitions, have the last color stop be the same as the first one:
There’s also a repeating-conic-gradient
function that can be used to create some interesting patterns with conic gradients:
As of 2020, only 85% of devices worldwide support the conic-gradient
property. Thankfully though, there’s a polyfill by @LeaVerou that we can use to start using conic gradients now.
To use the polyfill simply add the scripts for Prefix-free and the conic gradient polyfill itself before the closing body tag in your pages:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!