Guide
How to Create Beautiful CSS Gradients
Learn how linear and radial gradients work, how to pick color stops, and how to generate production-ready CSS gradient code.
By Sorawi Tools Team · Published July 22, 2026 · Updated August 1, 2026
How CSS Gradients Work
A CSS gradient is an image generated by the browser from a set of colors and instructions, with no image file involved. The two fundamental kinds are linear-gradient, which blends colors along a straight line, and radial-gradient, which blends colors outward from a point. Both accept a list of color stops, the points where specific colors appear, and the browser interpolates the colors between them. The simplest example is a two-color linear gradient: linear-gradient(to right, #6366f1, #ec4899) starts with indigo on the left and fades to pink on the right. Between the stops, every pixel gets a color computed by interpolating the two endpoint colors. The result is smooth, seamless, and renders instantly because it is pure CSS, not a downloaded image. Gradients are generated images in CSS terms, which means they can be used anywhere an image can: as a background, as a mask, or even as the background of a border by combining them with border-image. They also scale naturally, always matching the element they fill, which gives them an edge over pre-rendered gradient images that have to be re-exported at every size. Because a gradient is computed from discrete values, it is fully deterministic. The same declaration produces the same result in every modern browser, which makes gradients a dependable part of a design system rather than a decoration with unpredictable results.
Linear Gradients: Direction and Angle
The direction of a linear gradient is specified either by a keyword or by an angle. Keywords come in pairs: to top, to right, to bottom, and to left, plus the diagonal combinations to top right, to bottom right, to bottom left, and to top left. The direction describes the destination of the gradient, so to bottom fades from top to bottom. Angles give finer control and are measured clockwise from the top of the element. An angle of 0 degrees points toward the top, 90 degrees points to the right, 180 degrees points to the bottom, and 270 degrees points to the left. The popular diagonal example linear-gradient(135deg, #6366f1, #ec4899) points toward the bottom-right, producing the classic corner-to-corner look found in countless buttons and hero sections. There is a subtlety in how the browser measures a diagonal direction. The keyword to top right travels along a line at 45 degrees from the center of the element, while the angle 135deg also produces a bottom-right gradient, but the line is positioned so the color stops are distributed evenly along its length. For practical purposes the two usually look similar, but the keyword form computes distances from the corners while the angle form uses the full extent of the element. For most work, keywords are easier to reason about and angles are easier to tune precisely. If you want a gradient that leans only slightly off horizontal, no keyword exists for that, and an angle is the right tool.
Color Stops and Positioning
Color stops define where each color appears along a gradient, and they accept an optional position after the color. Without positions, stops are spaced evenly: linear-gradient(#6366f1, #ec4899) fades from indigo to pink with the halfway point exactly in the middle. Positions are given as percentages or lengths, and they let you shape the transition. A simple use of positions is a hard stop, two colors at the same point that produce a crisp edge instead of a fade: linear-gradient(to right, #6366f1 0%, #6366f1 50%, #ec4899 50%, #ec4899 100%) creates a clean two-tone background with no blending. Hard stops are a classic technique for stripes, progress bars, and alternating panels without any extra images. More stops create richer transitions. linear-gradient(to right, #6366f1, #22d3ee, #ec4899) fades indigo to cyan to pink, and the browser positions the three colors evenly by default, with the middle stop at 50 percent. Adding positions, like placing a bright accent at 20 percent, shifts the emphasis of the gradient. Every gradient renders with its color stops normalized: the first stop defaults to 0 percent and the last to 100 percent, and any stop outside that range is clamped. Positions beyond the element edge, such as a stop at 120 percent, simply extend the end color, which is a legitimate technique for pushing a subtle color wash across a whole section.
Radial Gradients: Shape and Position
Radial gradients radiate outward from a single point instead of following a line, and they are excellent for highlights, vignettes, and glow effects. The basic form is radial-gradient(#6366f1, #ec4899), which centers the gradient and blends from the first color at the center to the second color at the edge of the element. The shape adapts to the element by default: a square element produces a circular gradient, while a wide rectangle produces an ellipse that matches its proportions. You can force either shape explicitly with the keywords circle and ellipse. With circle, the gradient always stays circular even on a wide element, leaving any uncovered corners to take the end color. Positioning moves the center point with the at keyword: radial-gradient(circle at top left, #6366f1, #ec4899) centers the glow in the top-left corner. Position keywords, percentages, and lengths are all allowed, with at center as the default. Sizing terms are also available: farthest-corner sizes the gradient so it reaches the farthest corner from the center, and closest-side, closest-corner, and farthest-side behave similarly. In practice, farthest-corner is the default and works for most glows, while closest-side is useful for tight highlights on small elements like buttons. A radial gradient is also the standard building block for a subtle spotlight effect layered over a page background.
Real-World Uses for Gradients
Gradients are everywhere in modern interfaces, and knowing where they genuinely help makes the difference between a polished design and a noisy one. Buttons are the most common use: a subtle linear gradient from a lighter to a darker shade of the same color adds depth and a tactile quality that flat color lacks, and the browser can even animate a gradient's position on hover. Hero sections and landing pages lean on wide diagonal gradients to give large empty areas visual interest without resorting to heavy imagery. A soft two-color gradient like the indigo-to-pink example reads as brand-colored and stays fast, because it is computed at render time instead of shipped as a file. Radial gradients earn their place in subtle backgrounds and overlays. A faint radial glow behind a heading draws the eye, and a radial gradient layered over a photo with a transparent center and a dark edge creates a vignette that focuses attention on the middle of the frame. Hard-stop gradients produce stripes and progress indicators. Beyond decoration, gradients can carry meaning: temperature maps, signal strength bars, and rating scales all use color transitions as data encoding. And because gradients are CSS, they inherit accessibility behavior, so any text placed on top can be measured for contrast exactly as it will render.
How to Generate a Gradient
Writing gradient syntax from memory is easy to get subtly wrong, which is where the Gradient Generator comes in. It lets you pick colors visually, add and position multiple stops, choose a direction or shape, and see the result live. The tool then outputs the exact CSS declaration, ready to paste into a stylesheet. Everything runs in your browser, so your colors and settings never leave your device.
- 1Open the Gradient Generator tool.
- 2Add two or more color stops and pick each color with the color picker.
- 3Choose a direction or angle for a linear gradient, or a shape and position for a radial gradient.
- 4Drag the stops to reposition them and watch the preview update live.
- 5Copy the generated CSS and paste it into your stylesheet, or export it for use elsewhere.
Common Mistakes and Design Tips
The most common gradient mistake is picking two colors far apart in hue and watching the midpoint turn muddy gray. Interpolating between hues that sit opposite each other on the color wheel passes through desaturated territory in between. Keeping stops within a similar hue family, or deliberately using a mid-gray stop, produces cleaner blends. A second mistake is forgetting that gradients are relative to the element. The same declaration looks different on a button than on a full-width section because the browser stretches the gradient to fit. If a design calls for a consistent gradient across differently sized elements, the simplest fix is to apply the gradient to a shared container rather than to each element. Third, gradients can wash out text. A high-contrast two-color background makes white text illegible on the light half. Reserve strong gradients for backgrounds without text, or place text inside a solid panel, and always verify contrast ratios. Design tips that reliably improve results: use three stops instead of two for richer depth, keep the hue distance between neighboring stops modest, reserve radial gradients for glows and spotlights, and use hard stops deliberately for stripes. A final practical tip is to define gradients as CSS custom properties when you reuse them, so changing the palette means editing one variable instead of every declaration.
Gradient Accessibility and Performance
Two practical concerns rarely come up in gradient tutorials but matter on real pages: contrast and rendering cost. A gradient is a background, and like any background it has to keep text on top of it readable. The safest approach is to keep gradient areas as accents rather than full-page backdrops, and to test the specific colors you choose with a contrast checker before shipping. A vivid magenta-to-cyan gradient looks striking as a small button or a section divider, but the same gradient behind body text will fail WCAG contrast checks immediately. The second concern is rendering cost. Browsers paint gradients efficiently, and a CSS gradient is far cheaper than an equivalent raster image, but a full-viewport gradient with many stops and a large blur is still work for the compositor. Keep decorative gradients to one or two layers, avoid animating gradient positions in loops, and let the gradient sit behind content rather than trying to text-shadow text to compensate for low contrast. A gradient done well is a tool, not decoration: it directs the eye, establishes hierarchy, and can even reinforce brand color. Done carelessly, it becomes the thing that makes a page look dated.
Gradient Generator
Create beautiful CSS gradients with a visual editor. Pick colors, angles, and stops, then copy the CSS.
