Developer guide
Create CSS gradients that keep text readable
By MultiZest · · 4 min read
A gradient can create a useful visual hierarchy without an image download, but a background that looks attractive in isolation may make text hard to read. Treat the gradient shape, fallback color and foreground contrast as separate design decisions.
Choose the gradient for the shape you need
A linear gradient blends along a line and works for banners or subtle panel shading. A radial gradient spreads outward from an origin. A conic gradient rotates around a center, which can suit decorative diagrams but needs care around text.
In the CSS Gradient Generator, select a type and adjust the controls that apply to it. A linear angle changes direction. Radial and conic gradients interpret their origin differently, so inspect the preview rather than copying settings between types blindly.
Start with two colors and a fallback
Use a small number of stops while establishing the layout. Closely spaced stops can create a sharp boundary; more distant stops spread the transition. Extra colors can make it harder to predict the background beneath a label.
Provide a solid background color before the gradient declaration so text remains readable if the gradient is unavailable. The following example uses white text over a dark indigo range. Check the rendered result in its actual layout before using it.
.banner {
color: #ffffff;
background-color: #312e81;
background-image: linear-gradient(120deg, #312e81, #1e3a8a);
}Check the least favorable foreground/background pair
Use Color Contrast Checker for candidate opaque colors. For normal text, WCAG AA generally requires at least 4.5:1; large text uses 3:1. Those thresholds are evaluated against the actual adjacent background, not an average of the gradient colors.
Checking only the two endpoints may miss an unfavorable intermediate color or an overlaid image. Inspect every region behind the text at representative viewport sizes. If that is difficult, place the text on a solid panel or add a sufficiently opaque background layer and assess that final pair.
Test responsive and interactive states
A centered radial highlight may sit behind a button on a narrow screen even when it appears elsewhere on desktop. Check wrapped headings, focus indicators and hover states at the widths your layout supports.
Keep focus outlines visible and do not rely on a color change alone to communicate an error or selection. A decorative gradient should not make a disabled control appear interactive. Avoid unnecessary background animation, especially when a static background communicates the same information.
Copy the CSS and verify the actual page
Use the generator output as a starting declaration and merge it with your component styles. Check support in target browsers and inspect any fallback. Test the final stylesheet because another rule can override the background or text color.
CSS gradients eliminate a raster background request, but they are not automatically free of rendering cost. Complex, animated or oversized effects can still be expensive. Measure a real bottleneck before replacing a simple working style.
Review a heading after it wraps on a phone
A desktop heading may sit entirely over a dark corner of a gradient. On a narrow screen, its second line can move over the light center. Resize the actual component and inspect where each line lands rather than checking one fixed screenshot.
Use a solid backing for important copy when the gradient cannot maintain reliable contrast across layouts. The background can remain decorative elsewhere while the text receives a predictable readable surface.
Document the foreground as well as the gradient
Save the text color, relevant font size and component states with the generated background value. A later change from white to pale gray text can alter the result even if the gradient itself is untouched.
Test focus and hover states after integration, especially for links placed inside a decorative header. Contrast measurements belong to the rendered pair and state; one passing default-color example does not cover every interaction.
Try the tools used in this guide
Create linear, radial, and conic CSS background gradients with live preview and code export.
Color Contrast Checker →Check WCAG AA and AAA color contrast, preview text and compare normal text, large text and interface thresholds.
CSS & JS Minifier →Compress CSS and JavaScript code by removing comments, whitespace, and formatting.
Image Color Picker →Click or tap an image pixel to inspect its HEX and RGB values in your browser.