{"id":156,"date":"2026-10-18T21:10:25","date_gmt":"2026-10-18T21:10:25","guid":{"rendered":"https:\/\/refracttools.com\/blog\/?p=156"},"modified":"2026-10-18T21:10:25","modified_gmt":"2026-10-18T21:10:25","slug":"css-gradients-guide","status":"publish","type":"post","link":"https:\/\/refracttools.com\/blog\/css-techniques\/css-gradients-guide\/","title":{"rendered":"CSS gradients explained: linear, radial and conic"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">CSS has three gradient functions: <code>linear-gradient()<\/code> blends colours along a straight line at an angle, <code>radial-gradient()<\/code> spreads them outwards from a point in a circle or ellipse, and <code>conic-gradient()<\/code> rotates them around a centre like a colour wheel. Each has a <code>repeating-<\/code> version, all three work in every current browser, and because gradients count as images, you use them anywhere CSS accepts an image, most often <code>background<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-takeaways is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Key takeaways<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Linear for directional fades, radial for glows and spotlights, conic for pie charts, colour wheels and angular effects.<\/li>\n\n\n<li>Two colour stops at the same position make a hard line instead of a blend.<\/li>\n\n\n<li>Add <code>in oklch<\/code> to avoid a muddy grey middle when blending very different colours.<\/li>\n\n\n<li>Gradients cost no download and stay sharp at any size.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">How does linear-gradient() work?<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>.hero {\n  background: linear-gradient(135deg, #ff7a59, #7b5cff);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first value is the direction, and it is optional; without it the gradient runs from top to bottom. It can be an angle (<code>0deg<\/code> points up, <code>90deg<\/code> right) or a keyword such as <code>to right<\/code> or <code>to bottom left<\/code>. Then come the colour stops. With no positions, they are spaced evenly. Add a percentage to place a stop exactly, or a bare percentage between two colours to move the midpoint of the blend:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Orange holds until 20%, blend midpoint at 60% *\/\nbackground: linear-gradient(90deg, #ff7a59 20%, 60%, #7b5cff);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How does radial-gradient() work?<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>.spotlight {\n  background: radial-gradient(circle at 30% 20%, #ffd166, transparent 60%), #170c30;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You set the shape (<code>circle<\/code> or the default <code>ellipse<\/code>), optionally a size such as <code>closest-side<\/code> or <code>farthest-corner<\/code>, and the centre with <code>at x y<\/code>. Fading a colour to <code>transparent<\/code> over a solid background is the basis of glows, vignettes and soft lighting. Layering several of these is how <a href=\"\/blog\/css-techniques\/css-mesh-gradient\/\">CSS mesh gradients<\/a> are made.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How does conic-gradient() work?<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>.pie {\n  border-radius: 50%;\n  background: conic-gradient(#ff7a59 0 40%, #ffd166 0 65%, #7b5cff 0);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Colours sweep around the centre instead of across the box. Each stop is an angle or a percentage of the full turn. The example is a pie chart: a stop position of <code>0<\/code> means &#8220;start where the previous colour ended&#8221;, so each segment has hard edges. Conic gradients also make colour wheels, loading rings and the shine on a metallic button.<\/p>\n\n\n<aside class=\"tool-card tool-card--inline\"><span class=\"swatch\" style=\"background:linear-gradient(135deg,#ffb347,#ff5f6d,#3a1c71)\" aria-hidden=\"true\"><\/span><div class=\"tool-card__body\"><p class=\"tool-card__eyebrow\">Free tool<\/p><p class=\"tool-card__name\">CSS gradient generator<\/p><p class=\"tool-card__blurb\">Linear, radial and conic gradients with up to three stops.<\/p><\/div><a class=\"btn primary\" href=\"https:\/\/refracttools.com\/css-gradient-generator\/\">Try it free <span aria-hidden=\"true\">\u2192<\/span><\/a><\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">Which gradient type should you use?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Type<\/th><th>Looks like<\/th><th>Good for<\/th><\/tr><\/thead><tbody><tr><td>linear<\/td><td>A straight fade<\/td><td>Hero backgrounds, buttons, overlays on photos<\/td><\/tr><tr><td>radial<\/td><td>A glow from a point<\/td><td>Spotlights, vignettes, soft lighting, mesh gradients<\/td><\/tr><tr><td>conic<\/td><td>A sweep around a centre<\/td><td>Pie charts, colour wheels, angular shine, borders<\/td><\/tr><tr><td>repeating-linear<\/td><td>Stripes<\/td><td>Progress bars, warning tape, backgrounds<\/td><\/tr><tr><td>repeating-radial<\/td><td>Rings<\/td><td>Ripples, targets, retro patterns<\/td><\/tr><tr><td>repeating-conic<\/td><td>Rays or checkerboards<\/td><td>Sunbursts, transparency grids<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How do you make hard stripes with a gradient?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Put two colour stops at the same position and the browser draws a sharp line instead of a blend. Combined with a repeating gradient, that makes stripes with no image at all. Change the pixel values to make the stripes wider or narrower:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.stripes {\n  background: repeating-linear-gradient(\n    45deg,\n    #ffd166 0 12px,\n    #1a1020 12px 24px\n  );\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Two everyday gradient tricks<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Readable text over a photo<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A dark gradient from the bottom of a hero image makes white text readable without darkening the whole photo. Layer it above the image in the same <code>background<\/code>, so the gradient comes first in the list:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.hero {\n  background:\n    linear-gradient(to top, rgb(0 0 0 \/ .7), transparent 60%),\n    url(\"hero.webp\") center \/ cover;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Gradient borders with rounded corners<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>border-image<\/code> ignores <code>border-radius<\/code>, so use two backgrounds instead: a solid colour clipped to the padding box, and the gradient clipped to the border box. The gradient shows through only where the transparent border is.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.card {\n  border: 2px solid transparent;\n  border-radius: 16px;\n  background:\n    linear-gradient(#1a1020, #1a1020) padding-box,\n    linear-gradient(135deg, #ff7a59, #7b5cff) border-box;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How do you stop gradients looking muddy?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By default, browsers blend gradients in the sRGB colour space. Blending two very different hues, such as orange and blue, passes through a dull grey-brown in the middle. Three fixes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Interpolate in OKLCH<\/strong>: <code>linear-gradient(in oklch 90deg, #ff7a59, #2f8cff)<\/code> keeps the middle bright. It is supported in all current browsers; older ones ignore the whole declaration, so put a plain gradient before it as a fallback.<\/li>\n\n\n<li><strong>Add a middle stop<\/strong> with a colour that sits between the two on the colour wheel.<\/li>\n\n\n<li><strong>Choose neighbouring hues<\/strong>, such as orange to pink or teal to blue, which blend cleanly in any space.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-group is-style-refract-callout is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\"><strong>Banding:<\/strong> Large, smooth gradients can show visible bands of colour on some screens. A faint layer of noise hides them; see <a href=\"\/blog\/css-techniques\/css-grain-texture\/\">adding grain to CSS gradients<\/a>.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Can you animate a CSS gradient?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Not directly: browsers can&#8217;t transition between two gradient images. Two workarounds do the job. Make the gradient larger than the element with <code>background-size: 200%<\/code> and animate <code>background-position<\/code>, or register the colours or angle as custom properties with <code>@property<\/code>, which lets the browser interpolate them. Our guide to <a href=\"\/blog\/css-techniques\/css-gradient-text\/\">gradient text<\/a> uses the first approach for a shimmering heading. Either way, add a <code>prefers-reduced-motion<\/code> rule.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Build a gradient<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/refracttools.com\/css-gradient-generator\/\">CSS gradient generator<\/a> builds linear, radial and conic gradients with two or three stops, lets you move the midpoint and angle, and copies a ready-to-use rule. Its &#8220;Paste into&#8221; menu rewrites the code for Elementor, Divi, Bricks, Breakdance or the block editor. For layered, organic blends, try the <a href=\"https:\/\/refracttools.com\/mesh-gradient-generator\/\">mesh gradient generator<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Last checked: October 2026.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Sources: <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/gradient\/linear-gradient\" rel=\"noopener\" target=\"_blank\">MDN: linear-gradient()<\/a>, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/gradient\/conic-gradient\" rel=\"noopener\" target=\"_blank\">MDN: conic-gradient()<\/a>, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/color-interpolation-method\" rel=\"noopener\" target=\"_blank\">MDN: &lt;color-interpolation-method&gt;<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How linear, radial and conic gradients work in CSS, with copy-ready code for stripes, pie charts, text overlays and gradient borders, and how to stop blends turning muddy.<\/p>\n","protected":false},"author":1,"featured_media":155,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_refract_tool":"css-gradient-generator","footnotes":""},"categories":[8],"tags":[28,4,49],"class_list":["post-156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css-techniques","tag-colour","tag-css-generators","tag-gradients"],"_links":{"self":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":1,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":161,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/156\/revisions\/161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media\/155"}],"wp:attachment":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}