Choosing attractive colors will not determine where a gradient changes. The position of each stop controls the rhythm of the transition, so CSS gradient color stops deserve the same attention as spacing and typography. A hero overlay, a striped badge, and a progress bar each need a different setup.
Use the methods below to connect each CSS choice to a visible design problem. CSS Images Module Level 4 defines gradient stops, interpolation, and color hints. Those rules explain why small syntax changes produce very different results. Build the result in the CSS gradient generator and read the broader syntax notes in the CSS gradients guide.
In short
- Choose stops for the visual job, not simply from a palette.
- Set positions such as 0%, 35%, and 100% when default spacing misses the design.
- Use coincident stops for hard edges and color hints for midpoint control.
- Test transparency, color spaces, and text contrast inside the real component.
Choose stops based on the visual job of the gradient
Start by naming the result you need: a soft wash, a readable overlay, a sharp boundary, or a decorative text effect. A background wash can tolerate a long blend, while a badge may need a clean split between two colors.
For a hero image with white text, write down “dark behind the heading, lighter toward the image, invisible at the far edge” before choosing colors. A three-stop overlay could look like this:
.hero {
background: linear-gradient(90deg, #102a43 0%, #486581 45%, rgb(16 42 67 / 0) 100%);
}
The dark blue start supports the heading, the lighter middle stop opens the image, and transparent dark blue preserves a cleaner fade than an unspecified transparent endpoint. The failure this prevents is a visually attractive gradient that leaves text sitting on an unpredictable background. Linear, radial, and conic versions of the same idea live at linear, radial, and conic.
Set explicit stop positions instead of trusting default spacing
When a stop has no position, the browser distributes unspecified positions between the surrounding stops. That default works for a simple two-color blend, but it can put a three-color highlight in the wrong place.
Suppose the design needs a pale blue highlight near the left third of a panel. Give every stop a deliberate position:
.panel {
background: linear-gradient(110deg, #12355b 0%, #8ed1fc 35%, #f4f8fb 100%);
}
Here, 35% places the light stop near the intended focal area rather than at the browser’s evenly distributed midpoint. These positions describe points along the gradient line. They do not guarantee a particular perceived brightness, so inspect the rendered panel as well. Seed the colors from the palette generator when they should stay in one family.
Use adjacent stops to create hard color edges
A blended transition is the wrong tool for stripes, segmented progress bars, and two-tone badges. Two adjacent stops at the same position create a zero-length interpolation segment and an abrupt edge, as documented in the CSS Images specification.
.badge {
background: linear-gradient(90deg, #183b56 0%, #183b56 50%, #f6c85f 50%, #f6c85f 100%);
}
The paired 50% stops divide the badge without a blended band. For repeated stripes, use the same idea with repeating-linear-gradient(). Keep the positions intentional: changing 50% to 48% changes the width of both color regions, not just the location of the edge.
Add a color hint when the midpoint needs more control
A color hint changes where a two-color transition appears to reach its midpoint. It does not add a third final color, so it solves a different problem from inserting another stop.
.cover {
background: linear-gradient(90deg, #102a43 0%, 40%, #d9f0ff 100%);
}
The 40% hint tells the interpolation to place its midpoint earlier than the ordinary 50% position. Compare this with an extra color stop: an extra stop introduces a new color, while a hint changes the distribution of the transition between the existing colors. The CSS Images Module Level 4 color-hint rules provide the formal syntax and behavior.
Choose a color space that suits the transition
CSS can interpolate colors in different spaces, and the path between two stops changes with that choice. A transition written in a default sRGB-style setup can look different from one interpolated in OKLab.
.smooth {
background: linear-gradient(90deg, #164e63, #fef3c7);
background: linear-gradient(90deg in oklab, #164e63 0%, #fef3c7 100%);
}
The first line is the fallback for browsers that do not understand the in syntax. CSS Color Module Level 4 describes color spaces and interpolation. Treat OKLab as an option to test, not an automatic answer. Compare the rendered result in the browsers you support, especially when the gradient contains saturated colors or sits behind small text. The syntax can be valid while the visual result still misses the design. OKLCH for designers is the related note on perceptual spaces.
Use transparency stops without creating a muddy overlay
transparent means a fully transparent color, but interpolation still needs color information. An unspecified transparent endpoint can produce an unwanted cast as the gradient fades over an image.
.hero::after {
background: linear-gradient(
90deg,
rgb(0 0 0 / 0.82) 0%,
rgb(0 0 0 / 0.35) 55%,
rgb(0 0 0 / 0) 100%
);
}
This explicit alpha keeps the fade tied to black. Test it over both light and dark imagery. If the fade looks gray, blue, or dirty, inspect the endpoint color before changing the entire palette.
Check contrast and rendering at the actual stop positions
Text can cross several contrast conditions as it moves across a gradient. Checking only the first and last colors misses the light patch in the middle, where a heading often becomes hardest to read.
Use a short checklist:
- Render the real component at its smallest supported viewport.
- Check text over the lightest and darkest rendered regions in the contrast checker.
- Inspect the area around every deliberate stop, including a 35% highlight.
- Use WCAG contrast guidance when evaluating text requirements. Success Criterion 1.4.3 is about the background behind the text, and a gradient is more than one background. See the W3C understanding document for 1.4.3.
Color Mapper can generate the gradient and check solid pairs. A swatch alone cannot show how text sits over the gradient. For print, throw the blend away until a few flat colors remain and read CMYK-safe web palettes.
Validate the final gradient with a small browser test
Before shipping, inspect the stops rather than guessing at the colors. Confirm that the browser parses every stop, then compare the result with the visual job you wrote down.
- Inspect stop positions and look for accidental coincident stops.
- Compare the midpoint with the intended focal area.
- Test heading contrast over the lightest and darkest regions.
- Check the target browsers without assuming identical rendering.
For example, move a three-stop hero’s light color from 45% to 35% if the heading loses separation too early, then retest at the smallest viewport. This catches an unexpected midpoint, an accidental hard edge, or a muddy fade before those issues reach production.
Use the simplest stop setup that produces the intended result
Begin with two stops. Add explicit positions when spacing matters, a hint when the midpoint is wrong, and extra colors only when they solve a visible problem. Good CSS gradient color stops depend on both color selection and placement, so test the final CSS in the target component over real content. Open the gradient generator when you want the preview beside the code.
FAQ
What is a CSS gradient color stop?
A color, plus an optional position, along the gradient line. CSS Images Level 4 spaces missing positions evenly between the stops you did set. Build them in the gradient generator.
How do I make a hard edge?
Put two different colors at the same position. The blend between them has zero length, so the edge is sharp. The same pattern works in linear, radial, and conic gradients.
What is a color hint?
A percentage between two color stops with no color of its own. It moves the midpoint of the blend. It does not add a third color. The rules are in CSS Images Module Level 4.
Why does a fade to transparent look muddy?
The keyword transparent still interpolates from a color. Name the hue you are fading, such as rgb(0 0 0 / 0), and check the overlay on the real image.
Can text sit on the gradient?
Only if the lightest and darkest areas under the glyphs meet the contrast ratio you need. Sample both in the contrast checker. If either fails, move the type onto a solid card.