Color Gradients in Design: How to Use Them Well

Quick Answer

Use color gradients by keeping them to two close colors, blending in a perceptually uniform space like Oklab so the middle does not go muddy, and checking text contrast at the darkest and lightest point rather than the average. One gradient per screen. Flat color should stay your default.

Good gradients follow three rules. Keep the two colors close together on the color wheel, blend them in a perceptually uniform space so the middle does not turn grey, and check your text contrast at the worst point of the gradient rather than the average. Do those and most gradients look intentional. Skip them and you get the muddy, slightly dated look that gives gradients a bad name.

This guide is about the design judgment, not the syntax. If you want the code for linear, radial and conic gradients, our CSS gradient guide covers every type with copy-paste examples, and MDN Web Docs' gradient reference documents the full syntax for every gradient function. What follows is how to decide what to put in them.

When should you use a gradient at all?

Start from the assumption that you should not. Flat color is faster to read, easier to keep accessible, and almost never looks wrong. A gradient needs a reason.

Good reasons: you want to draw the eye to one specific area, like a hero section or a primary button. You want to suggest depth without a shadow. You need to fill a large empty area that would look flat and cheap in a single color. Or you are covering a photo with an overlay so text sits readably on top of it, which is probably the most defensible use of all.

Bad reasons: everyone else is doing it. It looks modern. The flat version felt boring. That last one is worth sitting with, because a design that feels boring in flat color usually has a layout or hierarchy problem, and a gradient will not fix it. It will just make the same problem shinier.

One per screen is the working limit. Gradients work by pulling attention, so two of them compete and both lose.

Which colors actually work together in a gradient?

Neighbours. Colors that sit near each other on the color wheel blend cleanly because the path between them is short and stays saturated the whole way.

The reliable combinations, roughly in order of how hard they are to get wrong:

What to avoid: complementary pairs sitting directly opposite each other, like red to green or blue to orange. The straight line between them runs through grey, and you get a dead zone in the middle. If your brand genuinely needs both, put a third color between them to route the blend around the dead spot, or send the blend the long way around the wheel, covered further down.

If you are building this into a brand system, our brand color guide covers how to pick the base palette first. Gradients should come out of the palette, not replace it. CSS can now derive the second stop from your brand color, so changing the brand color moves both ends; the syntax is in our CSS guide to relative color. A derived stop is related to the first, not guaranteed to look good, so check it at real size.

Want to try a blend before you commit to it? Try the free gradient generator →

Which direction should a gradient run?

On small, bounded shapes like buttons, cards and badges, light at the top and darker at the bottom. That reads as raised. Flip it and the same shape tends to read as pressed in or hollow. That is a shortcut your visual system takes.

Kleffner and Ramachandran, writing in Perception & Psychophysics in 1992, describe shape from shading as assuming a single light source illuminating the whole scene, shining from "above". They found that the time to detect a single shaded convex shape did not increase with the number of items in the display, and that left-right differences in luminance did not produce that pop-out. So if you want a button to feel pressable at a glance, a vertical gradient does work that a horizontal one does not.

The angle does not need to be exactly vertical. Sun and Perona asked "Where is the sun?" in Nature Neuroscience in 1998 and found that people's preferred lighting direction is not directly overhead but shifted to the left, linked to handedness, a preference they say is reflected in art spanning two millennia. A gradient running down and slightly to the right, around 165deg rather than the default 180deg, fits that. Anything that reads as "top, maybe top-left" will work.

When should you break the rule on purpose?

For angle syntax, see how linear gradients work in our CSS guide.

Why does the middle of your gradient look muddy?

This is the most common gradient problem. When every stop is a legacy sRGB color, which CSS Color Module Level 4 defines as hex colors, named colors, rgb(), hsl() or hwb(), the browser blends in gamma-encoded sRGB. The straight line between two saturated colors in that space passes through a less saturated region, so a vivid pink and a vivid blue meet in the middle as a washed-out lavender-grey.

The fix is to name the space the blend runs through. The W3C's CSS Images Module Level 4 adds a color interpolation method to gradients and notes that "choosing a polar, rather than rectangular, colorspace for gradient interpolation avoids desaturation". Oklab gives a cleaner straight blend; Oklch, a polar space, holds saturation the whole way across. The spec's own figure draws #F01 to #081 in Lab, sRGB and Oklab. The syntax, and the fallback that stops older browsers losing the background, are in our CSS guide to interpolation.

Complementary pairs. In a polar space there are two ways round the hue wheel, and CSS Color 4 lets you pick the longer arc. Blue to orange the long way sweeps through green and yellow instead of cutting across grey, with no third stop. That gives a wide, faintly rainbow effect, which suits a hero and rarely suits a button. If one end is white, black or grey, it has no hue to arc from, so this does not help.

A midpoint in the wrong place. If the colors and the space are right but the blend turns over too early or too late, move the midpoint with a color hint, a bare position between two stops, rather than adding a third color to choose and maintain. Pushing the midpoint away from centre also shortens the time a complementary blend spends in the dead zone. See color hints.

Fades to transparent. These stay clean in CSS because gradients interpolate with premultiplied alpha, which CSS Images Level 3 says "tends to produce more attractive transitions". If the same fade looks muddier in a design tool, fade to your own color at zero alpha there.

How do you keep text readable on a gradient?

Measure contrast at the worst point, not the average. That is the whole discipline.

A gradient running from light to dark will pass a contrast check at one end and fail at the other. Designers test the middle, see a comfortable number, and ship something that becomes unreadable in the corner. The failure is invisible to you because you know what the text says.

WCAG 2.2 success criterion 1.4.3 sets the bar at Level AA: at least 4.5 to 1 for normal text, and at least 3 to 1 for large text, where large means 18 point or 14 point bold, roughly 24px and 18.5px. The criterion also lists insufficient contrast caused by a background image as a failure, and a gradient background behaves the same way.

Three ways to handle it:

Check both ends with a real tool rather than by eye. Our contrast checker gives you the ratio, and the color accessibility guide explains it.

What about text filled with a gradient?

Gradient-filled letterforms cost you contrast at the extremes of the run, so use them on a headline, a logotype or a single number, and keep anything people need to read in flat color. Test the stop closest in lightness to the background, because that is the weakest point. MDN warns that if the background does not paint, the text can become unreadable, so always ship a solid fallback; the code is in our CSS guide to gradient text, and the forced colors case is below.

Is the contrast ratio the whole story?

For now, yes. The current WCAG 3 working draft says "the contrast algorithm used in WCAG 3 is yet to be determined", and W3C says WCAG 3 "is currently an incomplete draft" that "will not supersede WCAG 2". So meet 4.5 to 1 and 3 to 1 at the worst point, and if a heading passes but still looks thin against the busy part of the blend, fix it anyway.

Do gradient buttons pass accessibility checks?

They can, but there is a second criterion people forget about.

Text on the button is covered by 1.4.3 above. The button shape itself is covered by WCAG 2.2 success criterion 1.4.11, Non-text Contrast, but only in narrower cases than people assume. W3C says that if a control has visible content, such as readable text or a sufficiently contrasting icon, a border or other indication of its boundary is not required and is not subject to the 3 to 1 rule.

So a gradient button with a readable label does not need its fill to reach 3 to 1 against the page. Where 1.4.11 does bite is anything that carries meaning without text: an icon-only button, the check in a checkbox, a selected state, or a focus indicator. Those need 3 to 1 against the colours next to them, and on a gradient the colour next to them changes along the run, so check the weakest point.

That includes the focus ring: one that vanishes against the dark end of the gradient loses keyboard users.

Do gradients make buttons look more clickable?

They can help. In a 2017 eyetracking study written up by Kate Moran, the Nielsen Norman Group showed 71 people nine web pages, each in a version with strong clickability signifiers and one with weak ones. To build the strong versions the researchers added shadows, gradients and text treatments. On the weak versions, people spent 22% more time on the page and made 25% more fixations.

Keep it subtle, light at the top as in the direction section, let the label do most of the work, and only use the treatment on things people can press, or the signal stops meaning anything.

Do gradients work for people with color blindness?

Decorative ones, mostly fine. But once a gradient encodes a value, a heatmap, a red-to-green status bar, a chart legend, it becomes information, and contrast ratios will not tell you whether everyone can read it.

Crameri, Shephard and Heron, writing in Nature Communications in 2020, cite the estimate that worldwide 0.5 per cent of women and 8 per cent of men have a color-vision deficiency. They add that rates almost disappear in populations from sub-Saharan Africa and are likely significantly higher in populations with a larger fraction of white people, Scandinavia being their example.

Two separate things make a gradient unreadable. The first is red and green at similar lightness: the paper says color maps like that cannot be read by a large fraction of the readership. Vary lightness as well as hue. The second is uneven perceptual spacing, which affects everybody. In rainbow maps, the authors note, yellow is the brightest color and attracts the eye the most, and the distortion can exceed seven percent of the displayed data variation. A perceptually uniform map, they write, weights the same data variation equally across the whole range.

So never encode meaning in hue alone, pair the color with a label, an icon or a pattern where it matters, and test in greyscale. Our guide to color accessibility and WCAG goes further.

How should a gradient change in dark mode?

Rebuild it, don't invert it. A gradient tuned against a white page almost always looks wrong against a dark one, and flipping the stops makes it worse rather than better. On white, a mid-saturation gradient reads as a tint behind the content. On a near-black surface the same colors can become the loudest thing on the screen, competing with the text they were meant to sit under.

Serve the dark version with the prefers-color-scheme media feature, which Media Queries Level 5 says reflects the user's desire that the page use a light or dark color theme. Then re-measure text contrast at the worst point of the new gradient, because neither the background nor usually the text color carries over. Our dark mode color guide covers the wider palette work.

What happens to your gradient in forced colors mode?

It disappears. The W3C CSS Color Adjustment Module Level 1 describes forced colors mode, the feature behind Windows High Contrast and similar settings, as an accessibility feature intended to increase the readability of text through color contrast. In that mode background-image computes to none unless it contains a url() function, and a CSS gradient has none. box-shadow and text-shadow compute to none as well, taking out the other two depth cues designers lean on.

You can opt an element out with forced-color-adjust, but overriding a setting someone turned on for accessibility is usually the wrong instinct. Design so the gradient was decoration all along. The media query and property syntax are in our CSS guide to forced colors.

What happens to your gradient on a wide-gamut screen?

It can look like a different gradient. CSS Color 4 publishes gamut volumes for the predefined color spaces in millions of Lab units: sRGB 0.820, display-p3 1.233, rec2020 2.042. An out-of-gamut color is gamut mapped for display, producing what the spec calls a similar-looking but lower chroma color.

On a gradient, the stops furthest outside sRGB are pulled in hardest while the others barely move, so the ramp can go slack exactly where you put the most saturation. It is easy to write a valid oklch stop with more chroma than sRGB can hold, because the syntax does not stop you.

Do animated gradients need special handling?

Yes. The moment a gradient animates on its own, it becomes moving content. WCAG 2.2 success criterion 2.2.2, Pause Stop Hide, covers moving content that starts automatically, lasts more than five seconds, and is presented in parallel with other content. Where all three are true, users need a way to pause, stop or hide it, unless the movement is essential.

That criterion is Level A, the minimum bar, so a page can get 4.5 to 1 contrast perfect and still fail because the background loops forever behind the text. The conditions are cumulative: a five-second intro that settles is fine, and so is a gradient that only moves on hover. The infinite loop is what catches you.

The prefers-reduced-motion feature in Media Queries Level 5 detects whether the user has asked the system to minimize motion. Switch the animation off for those people, and make the static end state look finished.

On cost: a static gradient is painted once and is not a performance problem. An animated one repaints every frame unless you move a layer with opacity or transform instead. The @property registration that lets gradient colors animate, and the cheaper alternatives, are in our CSS guide to animating gradients.

What causes gradient banding and how do you fix it?

Banding is the visible stepping you sometimes see across a large gradient, where a smooth blend turns into a set of stripes. It happens when the gradient covers a wide area with very few color values available to describe the change, so the display rounds neighbouring pixels to the same value and you see the joins.

It shows up most on large hero backgrounds, on subtle gradients between two very similar colors, and on darker gradients where there is less headroom to work with.

What helps:

Which gradient styles look current and which look dated?

Three styles read as current: soft two-stop blends that behave like light rather than paint, mesh gradients with several colors bleeding into each other, and grainy gradients with noise laid over the top. The dated ones are corner-to-corner rainbows, hard diagonal splits, and anything with a glossy highlight bar across it.

The common thread is restraint plus texture. For the broader palette picture, our web design color trends guide covers where gradients sit alongside everything else.

Mesh gradients have no CSS primitive. In the browser you fake them by stacking three or four radial-gradient() layers at different positions, each fading to transparent so the overlaps do the blending, or with a heavily blurred conic gradient. Mesh fakes have more color pairs meeting each other than a two-stop gradient, so blend them in Oklab.

Grainy gradients solve the banding problem above as well as looking current. The browser-native noise source is SVG's feTurbulence filter primitive, defined in the W3C Filter Effects Module Level 1. Generate one small noise tile, bake it into an image, and overlay it at low opacity rather than filtering a large element live. Grain you can consciously see has gone too far.

Repeating gradients, stripes and hatches, are cheap to write and easy to overdo. A subtle hatch behind a card reads as texture; the same pattern at full contrast across a hero reads as a test image, and it puts your text on two colors at once. The syntax is in our CSS guide to repeating gradients.

Which gradient mistakes make a design look amateur?

Five, in rough order of how often they show up.

Too many colors. Two is right for nearly everything. Three when you need a shift the eye can follow across a long space. Four or more and you have made a rainbow, and rainbows are very hard to use without looking like a free template.

Complementary pairs blended straight through the middle. Covered above. The grey dead zone is the giveaway.

Gradients on small elements. On a 24px icon or a thin border, the shift is too small to perceive. You have added complexity nobody can see.

Gradients behind body text. Even when contrast technically passes, a shifting background makes sustained reading harder. Save gradients for headings, heroes and decorative areas.

Competing gradients. One per screen. Two gradients fighting for attention read as busy rather than rich, and neither gets the emphasis you were after.

What else do people ask about gradient design?

Why does my gradient look muddy or grey in the middle?

Because a gradient with hex, rgb() or hsl() stops blends through sRGB by default, and the straight line between two saturated colors in that space passes through a desaturated zone. The W3C CSS Images Module Level 4 notes that choosing a polar rather than rectangular colorspace avoids this, since spaces like LCH and Oklch are inherently chroma-preserving. Adding in oklab to your gradient usually removes the grey dip in one line, and in oklch keeps the colors fully saturated.

How many colors should a gradient have?

Two for almost everything. Three when you genuinely need a shift the eye can follow, such as a long hero background. Beyond three you are usually decorating rather than designing, and every extra stop adds another place the gradient can go muddy or clash with text sitting on top of it.

Can you put text on top of a gradient?

Yes, but you have to check contrast at the worst point of the gradient, not the average. WCAG 2.2 success criterion 1.4.3 requires at least 4.5 to 1 for normal text and 3 to 1 for large text at Level AA, where large means 18 point or 14 point bold. Insufficient contrast caused by a background image is a listed failure, and a gradient behaves the same way.

What contrast do gradient buttons need?

If the button has a readable text label, its fill and edge do not need to reach 3 to 1 against the page: W3C says a boundary is only required when nothing else identifies the control. The label must meet 1.4.3, and anything that carries meaning without text, such as an icon, a selected state or a focus indicator, needs 3 to 1 against the colours next to it under WCAG 2.2 success criterion 1.4.11, checked at the weakest point of the gradient.

When should you not use a gradient?

Behind dense body text, on small UI elements where the shift is invisible anyway, and anywhere you have already used one nearby. Gradients work by drawing the eye, so two competing gradients on one screen cancel each other out. Flat color is the safer default and a gradient should be a deliberate exception.

Build a linear, radial or conic gradient with the free generator. Open the gradient generator →

Which sources is this based on?

Specifications are living documents, so check the current text before relying on a detail.