How to use the CSS conic-gradient() function?
conic-gradient() creates a conical color transition rotating around the center point, suitable for pie charts, color wheels or decorative circular designs implemented in pure CSS; 1. Unlike linear-gradient() and radial-gradient(), colors are arranged clockwise from the top along the circle; 2. The basic syntax is background: conic-gradient(color1, color2, ...); 3. The starting angle can be set through from(), such as from 45deg; 4. Use percentage color scales to control each segment color range, such as red 0 70% means red accounts for 70% circumference; 5. Create gaps between segments by inserting transparent or background color segments (such as 1%); 6. Combining background-size and background-position It can simulate ring graph effects; 7. It is supported by modern browsers, but not by IE. It can detect features through @supports and provide alternative styles; this method can realize simple data visualization without images or JavaScript, which is complete and efficient.
The conic-gradient()
function in CSS is used to create a gradient that rotates around a center point, with colors transitioning in a circular, cone-like pattern. It's especially useful for creating pie charts, color wheels, or decorative radial designs directly in CSS—no images or JavaScript required.

Here's how to use it effectively.
What conic-gradient()
does
Unlike linear-gradient()
(which goes side to side) or radial-gradient()
(which spreads outward from a center), conic-gradient()
places colors around a circle, starting from the top and moving clockwise.

Basic syntax:
background: conic-gradient(color1, color2, ...);
Example:

div { width: 200px; height: 200px; background: conic-gradient(red, yellow, lime, blue); border-radius: 50%; }
This creates a circular gradient that looks like a color wheel sliced into four sections.
Control the starting angle and rotation
By default, the gradient starts at the top (0deg). You can change this using the from()
syntax.
background: conic-gradient(from 45deg, red, blue, green);
This rotates the entire gradient so it starts at 45 degrees (top-right).
You can also define how much each color takes up by specifying color stops:
background: conic-gradient(from 90deg, red 0 25%, yellow 25% 50%, lime 50% 75%, blue 75% 100%);
This creates four equal 90-degree slices, starting from the right side.
? Think of each color as occupying a "wedge" — the percentage defines how much of the circle it covers.
Create a pie chart with conic-gradient
You can simulate a pie chart by assigning precision color stops.
Example: A pie chart with 70% red, 20% yellow, 10% green:
.pie { width: 200px; height: 200px; border-radius: 50%; background: conic-gradient( red 0 70%, yellow 70% 90%, green 90% 100% ); }
No extra HTML or JS — just pure CSS. Great for simple data visualizations.
Add gaps or borders between segments
To add space between slices (like a donut chart with gaps), use multiple backgrounds or layer shadows, but a simpler trick is to insert thin contrasting segments:
background: conic-gradient( red 0 69%, transparent 69% 70%, yellow 70% 89%, transparent 89% 90%, green 90% 99%, transparent 99% 100% );
This creates 1% transparent gaps between each color — use white or background color instead of transparent if you want visible borders.
Combine with background-size
and border-radius
To make the gradient appears as a ring (donut style), you can layer it over another background:
.donut { width: 200px; height: 200px; border-radius: 50%; background: conic-gradient(red 0 30%, yellow 30% 70%, lime 70% 100%), white; /* Center color */ background-size: 80% 80%; /* Shrink gradient to create a hole */ background-position: center; background-repeat: no-repeat; }
Alternatively, use a pseudo-element or padding trick for a true ring effect.
Browser support and fallbacks
conic-gradient()
is supported in all modern browsers (Chrome, Firefox, Safari, Edge), but not in Internet Explorer .
If you need fallbacks:
.fallback { background: red; /* Fallback color */ background: conic-gradient(red, blue); }
Or use @supports
for feature detection:
@supports (background: conic-gradient(red, blue)) { .chart { background: conic-gradient(red, blue); } }
Basically, conic-gradient()
is powerful for circular designs when you need color weddings. Use it with border-radius: 50%
for circles, control slices with stop percentages, and tweak the start angle as needed. It's not for everyone, but when you need a quick pie slice or color wheel, it's surprisingly capable.
The above is the detailed content of How to use the CSS conic-gradient() function?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Backdrop-filter is used to apply visual effects to the content behind the elements. 1. Use backdrop-filter:blur(10px) and other syntax to achieve the frosted glass effect; 2. Supports multiple filter functions such as blur, brightness, contrast, etc. and can be superimposed; 3. It is often used in glass card design, and it is necessary to ensure that the elements overlap with the background; 4. Modern browsers have good support, and @supports can be used to provide downgrade solutions; 5. Avoid excessive blur values and frequent redrawing to optimize performance. This attribute only takes effect when there is content behind the elements.

Theaspect-ratioCSSpropertydefinesthewidth-to-heightratioofanelement,ensuringconsistentproportionsinresponsivedesigns.1.Itisapplieddirectlytoelementslikeimages,videos,orcontainersusingsyntaxsuchasaspect-ratio:16/9.2.Commonusecasesincludemaintainingres

1. Binance is known for its huge transaction volume and rich trading pairs. It provides diversified trading models and perfect ecosystems. It also ensures the security of user assets through SAFU funds and multiple security technologies and attaches great importance to compliant operations; 2. OKX Ouyi provides a wide range of digital asset trading services and unified trading account models, actively deploys the Web3 field, and improves transaction security and experience through strict risk control and user education; 3. gate.io Sesame opens the door and has good currency speed and rich currency, provides diversified trading tools and value-added services, adopts multiple security verification mechanisms and adheres to the transparency of asset reserves to enhance user trust; 4. Huobi provides one-stop digital asset services with deep industry accumulation, with strong transaction depth and

The:emptypseudo-classselectselementswithnochildrenorcontent,includingspacesorcomments,soonlytrulyemptyelementslikematchit;1.Itcanhideemptycontainersbyusing:empty{display:none;}tocleanuplayouts;2.Itallowsaddingplaceholderstylingvia::beforeor::after,wh

Use hidden checkboxes and CSS's :checked pseudo-class combined with adjacent sibling selectors ( ) to control content display; 2. The HTML structure contains input, label and content div for each collapsed item; 3. Smooth expansion/collapse animations by setting max-height transition; 4. Add open/close status icons with pseudo-elements; 5. Use radio types to implement single-open mode, while checkbox allows multiple openings. This is an interactive foldable menu implementation that requires no JavaScript and is compatible with modern browsers.

Use CSSclip-path to create non-rectangular shapes in the browser without additional images or complex SVG; 2. Common shape functions include inset(), circle(), ellipse() and polygon(), where polygon() implements custom shapes by defining coordinate points, which is suitable for creating creative designs such as dialog bubbles; 3. clip-path can achieve dynamic effects through CSS transition or keyframe animation, such as circle expansion during hovering, but only supports inter-shape animations of the same type and number of vertices; 4. Pay attention to responsiveness and accessibility to ensure that the content is still available when not supported, the text is readable, avoid excessive cropping, and control the number of polygon vertices to optimize performance. At the same time, it is necessary to know that

vw and vh units achieve responsive design by associating element sizes with viewport width and height; 1vw is equal to 1% of viewport width, and 1vh is equal to 1% of viewport height; commonly used in full screen area, responsive fonts and elastic spacing; 1. Use 100vh or better 100dvh in the full screen area to avoid the influence of the mobile browser address bar; 2. Responsive fonts can be limited with 5vw and combined with clamp (1.5rem, 3vw, 3rem) to limit the minimum and maximum size; 3. Elastic spacing such as width:80vw, margin:5vhauto, padding:2vh3vw, can make the layout adaptable; pay attention to mobile device compatibility, accessibility and fixed width content conflicts, and it is recommended to give priority to using dvh first;

TheCSSfilterpropertyallowsvisualeffectslikeblur,brightness,andgrayscaletobeapplieddirectlytoHTMLelements.1)Usethesyntaxfilter:filter-function(value)toapplyeffects.2)Combinemultiplefilterswithspaceseparation,e.g.,blur(2px)brightness(70%).3)Commonfunct
