How to Create CSS Gradients

· 5 min read

CSS gradients let you create smooth color transitions without image files. They are lighter than images, scale perfectly to any screen size, and are easy to customize. A typical decorative gradient saves 20-100 KB compared to a equivalent JPG or PNG, and scales to any resolution without quality loss.

Types of CSS gradients

Linear gradient: colors transition in a straight line (top to bottom, left to right, or any angle).

background: linear-gradient(135deg, #667eea, #764ba2);

Radial gradient: colors radiate outward from a center point in a circular or elliptical pattern.

background: radial-gradient(circle, #667eea, #764ba2);

Conic gradient: colors rotate around a center point, like a color wheel.

background: conic-gradient(from 0deg, #667eea, #764ba2, #667eea);

How to create gradients visually

  1. Select the gradient type: choose linear or radial and set the angle or position.
  2. Add color stops: click to add colors at different positions along the gradient. Adjust each color and its position.
  3. Copy the CSS: copy the generated code and paste it into your stylesheet.

Using a visual generator is faster than writing gradient syntax by hand, especially when you are experimenting with multiple color stops.

A brief history of CSS gradients

Before CSS gradients existed, web designers had to use background images for any gradient effect: tile a single-column GIF horizontally, or slice a Photoshop PSD into multiple JPGs. This worked but added file weight, network requests, and pixelation when zoomed.

WebKit added the first -webkit-gradient() implementation in Safari 4 (June 2009) with a verbose, hard-to-read syntax. Firefox 3.6 (January 2010) followed with -moz-linear-gradient(). The CSS Working Group standardized the unprefixed linear-gradient() and radial-gradient() in CSS Image Values Level 3 (2012), at which point browser prefixes started disappearing.

Conic gradients (conic-gradient()) arrived much later, first shipping in Chrome 69 (September 2018) and reaching all major browsers by Safari 12.1 (March 2019). They enable visual patterns that were previously impossible without images: pie charts, color wheels, checkerboards, sunburst patterns.

CSS gradients are now considered baseline browser features. Almost any gradient effect you might want is achievable in CSS, with no images or JavaScript needed.

Common gradient patterns

Hero section background: a subtle two-color gradient adds depth without distracting from text.

background: linear-gradient(135deg, #0f172a, #1e3a5f);

Button highlight: a slight gradient makes buttons feel three-dimensional.

background: linear-gradient(180deg, #3b82f6, #2563eb);

Overlay on images: a gradient overlay improves text readability over photos.

background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.7));

Accent border: use a gradient as a border for visual interest.

border-image: linear-gradient(90deg, #667eea, #764ba2) 1;

Animated mesh gradient: stack multiple radial gradients and animate the positions.

background:
  radial-gradient(at 20% 30%, #667eea 0%, transparent 50%),
  radial-gradient(at 80% 70%, #764ba2 0%, transparent 50%),
  #0f172a;

Glass morphism backdrop: pair a low-opacity gradient with a backdrop-filter blur.

background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
backdrop-filter: blur(10px);

Color stop positioning

By default, color stops are evenly distributed. You can override their positions to control where each color appears:

/* Yellow in the middle 60%, fading to red at edges */
background: linear-gradient(90deg, red 0%, yellow 20%, yellow 80%, red 100%);

You can also use hard stops to create stripes or geometric patterns without antialiasing:

/* Two-color stripes with no transition */
background: linear-gradient(45deg, #667eea 50%, #764ba2 50%);

The trick is to put two color stops at the same position. The browser does not interpolate between them, producing a sharp edge.

When to use gradients vs solid colors vs images

A common pattern is to layer all three: a solid color base, a CSS gradient overlay, and a low-opacity texture image on top.

Common pitfalls

Tips

Privacy

The CSS gradient generator runs entirely in your browser. The colors you choose, the gradient configurations you experiment with, and the CSS you generate never leave your device. There is no telemetry, no usage tracking, no upload of your design choices. For tools used during design exploration, that matters: the colors and patterns you try out can reveal upcoming brand directions, unannounced product themes, or client work under NDA. Browser-only generation keeps all of that on your machine.

Frequently Asked Questions

Do CSS gradients work in all browsers?

Yes. Linear and radial gradients are supported in all modern browsers, including Chrome, Firefox, Safari, and Edge. Conic gradients have slightly less support but work in all current browser versions.

Can I use more than two colors?

Yes. CSS gradients support as many color stops as you want. Each stop defines a color and a position along the gradient.

Do gradients affect page performance?

No. CSS gradients are rendered by the browser and are much lighter than image files. They scale perfectly to any screen size with zero additional download.

Can I animate a gradient?

Not directly with a CSS transition on the gradient property, but you can animate the background-position or use CSS custom properties with @property to create smooth gradient animations.