UtilityBase logoUtilityBase

2 min read

How to Build a CSS Gradient

Learn how linear and radial CSS gradients work, how angle and color stops shape them, and how to generate clean, copy-ready gradient code fast.

Linear vs Radial Gradients

A CSS gradient is a smooth blend between two or more colors rendered as an image you can use for a background. The two most common types are linear and radial. A linear gradient runs its colors along a straight line set by an angle, while a radial gradient spreads its colors outward from a center point in rings.

The choice shapes the mood of a design. Linear gradients feel directional and are great for headers, buttons, and full-page backdrops. Radial gradients feel like a glow or spotlight and work well for focal points, badges, and soft vignettes behind content.

How Angles and Direction Work

In a linear gradient, the angle sets the direction of the blend. In CSS, 0deg points straight up, 90deg runs left to right, and 180deg runs top to bottom. So linear-gradient(90deg, red, blue) starts red on the left and ends blue on the right. You can also use keywords like to right or to bottom right instead of degrees.

A radial gradient does not use an angle. Instead it spreads from a center outward, and you control its shape (circle or ellipse) and how far the colors reach. Understanding this difference helps you predict the result before you write a single line of code.

Building One Step by Step

The generator lets you pick colors, set the type, and adjust direction while watching a live preview. When it looks right, you copy the code and drop it straight into your stylesheet.

  1. 1Open the CSS Gradient Generator and choose linear or radial as the gradient type.
  2. 2Pick your first and last colors, then add extra color stops if you want a multi-color blend.
  3. 3For a linear gradient, set the angle, for example 90deg for a left-to-right fade.
  4. 4Drag each color stop to control where one color hands off to the next.
  5. 5Watch the live preview update, then copy the generated background property into your CSS.

Practical Tips for Clean Results

Keep contrast in mind. If text sits on top of a gradient, make sure the darkest and lightest regions still leave the words readable, or overlay a semi-transparent layer. Subtle, closely related colors usually look more professional than clashing opposites.

Gradients render entirely in the browser, so they add no image weight and scale crisply at any size. Save the generated code as a reusable snippet, and remember you can layer multiple gradients or combine them with solid colors for richer effects.

Frequently asked questions

What angle makes a left-to-right gradient?

Use 90deg. In CSS, 0deg points up and angles increase clockwise, so 90deg runs the colors from the left edge to the right edge of the element.

Can I use more than two colors?

Yes. You can add several color stops, and each stop can be positioned along the line or radius. This lets you create rainbow effects or smooth multi-tone brand backgrounds.

Do CSS gradients slow down a page?

Not meaningfully. Gradients are drawn by the browser rather than loaded as image files, so they add no download weight and stay sharp at any screen size or zoom level.

Tools mentioned in this guide

Keep reading