What Is a CSS Gradient?
A CSS gradient is a programmatically generated image: the browser computes a smooth transition between two or more colors and paints it wherever an image could go — background-image, borders (via border-image), even text (with background-clip). Because it is math instead of a file, a gradient costs a few dozen bytes, renders razor-sharp on any display, and adapts when you resize. Every declaration has the same anatomy: a type and angle, then a comma-separated list of color stops, each optionally positioned — linear-gradient(135deg, #ff5e7a 0%, #7c3aed 50%, #06b6d4 100%).
Linear, Radial, and Conic: Which Type When
- Linear — colors flow along a straight line at an angle. The default for heroes, buttons, and banners; 90° blends top-to-bottom, 135° gives the classic diagonal.
- Radial — colors radiate from a center point in a circle or ellipse. Perfect for spotlights, glows, vignettes, and soft washes behind cards.
- Conic — colors sweep around a center like a clock hand, from a start angle to a full turn. The native choice for pie charts, donuts, gauges, and color wheels; with hard stop positions it draws crisp sectors.
Color Stops: How Positioning Works
Each stop has a color and a position (0–100% along the gradient line). Between stops the browser interpolates; before the first stop and after the last, colors stay solid. Move two stops closer together and the transition compresses into a hard-edged blend; put them at the same position and you get a hard line — the trick behind striped and conic-sector effects without any image. This generator gives each stop a slider so you can drag the transition points while watching the canvas, and supports 2–6 stops: two for classic fades, three for the popular tri-color washes, more when a chart scale demands it.
Angles and Directions Explained
For linear gradients the angle points where the gradient is heading, measured clockwise from “to top”: 0deg = bottom→top, 90deg = left→right, 180deg = top→bottom, 135deg = top-left→bottom-right (the favored diagonal). Keywords work too — to right, to bottom left — but degrees are what design tools export, and they behave the same everywhere. Radial and conic gradients position instead: circle at center, at 25% 75% — moving the center is how you push a glow where it matters.
Keeping the Middle from Going Muddy
Blend two complementary colors (red→green) and the midpoint math averages their RGB values into a gray sludge. Fixes, in order of preference: route through a third color (red → amber → green keeps the journey warm), stay in one hue family and vary lightness instead, or use near-neighbors from the color wheel (violet→pink→coral never muddies). The curated swatch palette in this tool is arranged so adjacent picks blend cleanly — the random shuffle is biased toward harmonies for the same reason.
Gradients and Accessibility
Two checks keep gradients inclusive. Text contrast: WCAG’s 4.5:1 requirement applies at the worst spot — measure the lightest stop under your text, not the average, or dark text on a light-to-dark wash fails at one end. Decoration: gradients carry no meaning, so never use color position alone to encode information a chart user needs. One more practical note: smooth, wide gradients can band on 8-bit displays; adding a third midpoint stop or a whisper of noise dithers the transition visibly better.
Where Gradients Shine (and Where They Do Not)
Gradients excel as backgrounds for content (heroes, banners, empty states), as brand accents (buttons, icons, borders), and as data encodings (scales, gauges). They struggle as backgrounds for busy text — a high-contrast rainbow behind a paragraph guarantees poor readability — and they date quickly when oversaturated: the 2016 purple-to-teal look is instantly recognizable. The modern recipe: low saturation, close hues, subtle angle, generous dark-mode variant. If the gradient is the loudest thing on the page, it is doing too much.
Step-by-Step: Using the CSS Gradient Generator
- Choose the type. Linear for banners and buttons, radial for glows and washes, conic for wheels and gauges.
- Set your stops. Add up to 6, pick colors from the palette, or shuffle for a curated random starting point.
- Dial the angle. 135° is the modern default for linear; nudge ±20° to change the energy without changing the palette.
- Drag stop positions to control where the blend happens — pull stops together for punchier transitions.
- Check it against your content — text over gradient needs contrast at the lightest point.
- Copy the CSS and paste it into your stylesheet or design token file.
Ready to Build Your Gradient?
You know the three types, how stops and angles steer the blend, why complements turn muddy and how to route around it, and what accessibility demands. Scroll back up, pick your colors, and copy a production-ready gradient declaration in seconds.
