Developer

CSS Gradient Generator

Create beautiful CSS gradients with live preview. Choose colors, direction, and copy the CSS code.

%
%
background: linear-gradient(to right, #667eea 0%, #764ba2 100%);

Designing smooth color transitions with CSS

Gradients are everywhere in modern web design: hero backgrounds that fade from one color to another, buttons with subtle depth through color shifts, and backgrounds that draw the eye across the page. Before CSS gradients, designers had to create images in Photoshop and embed them as files—wasteful and inflexible. CSS gradients (introduced in CSS3) let you define these smooth transitions in pure code, resulting in infinitely scalable, responsive backgrounds that can animate and adapt to any viewport.

Three types exist: linear (colors flow in one direction), radial (colors radiate from a center point), and conic (colors flow around a center, like a color wheel). This tool focuses on linear and radial, the most common. Each gradient defines color stops—points where specific colors occur—and the browser interpolates between them using smooth color blending. Hard stops (same position for two colors) create sharp stripes instead of blends.

How CSS gradients work

A CSS gradient is a generated image, so it can go anywhere a background-image property works: background, border-image, even mask-image. The syntax is straightforward: specify the direction or shape, then list color stops at positions. Linear gradients use directions (to right, 45deg, etc.). Radial gradients use shapes and positions (circle at center, ellipse at top-left, etc.).

Color stops define where colors exist. The format is color position, where position can be a percentage or length. If you omit positions, the browser spaces colors evenly. Example: linear-gradient(to right, red 0%, yellow 50%, green 100%) blends red to yellow in the left half, yellow to green in the right half.

Hard stops create visible stripes: red 50%, blue 50% creates a sharp line at the 50% mark. This is how you make striped backgrounds, flags, or layered designs without multiple elements.

Linear vs. radial gradients

  • Linear gradients. Colors flow in a straight line (left, right, diagonal, etc.). Use for hero backgrounds, button hovers, and directional transitions. Simplest and fastest.
  • Radial gradients. Colors emanate from a center point outward. Use for spotlight effects, vignettes, and circular designs. More complex but striking visually.
  • Conic gradients. Colors rotate around a center (like a color wheel). Less common but useful for progress rings, pie charts, and circular UIs.

Performance and best practices

  • Zero file size.Gradients are pure CSS, not images. They scale perfectly and don't require additional HTTP requests.
  • Responsive. Gradients adapt to any viewport without resizing or stretching artifacts.
  • Animatable. You can transition between gradients with CSS animations, though browser support varies.
  • Contrast and accessibility. Ensure text over gradients meets WCAG contrast ratios. Test dark text on light gradients and vice versa.
  • Browser support. All modern browsers support linear and radial gradients. Older browsers (IE 9 and below) need fallback solid colors or images.

Frequently asked questions

What's a “hard stop” gradient?

A hard stop is when two colors exist at the same position, creating a visible line instead of a smooth transition. Example: linear-gradient(to right, blue 50%, red 50%) creates a sharp vertical line at the midpoint. Useful for stripes, flags, or layered designs.

Can I animate gradients?

CSS animations struggle with gradients because they're not simple properties. You can transition gradient-related properties in some cases, but smooth animations between different gradient definitions require JavaScript. Background size animations are a workaround.

Why is the gradient pixelated or banded?

Banding happens when there aren't enough color transitions (typically with very smooth gradients over large areas). Add more color stops or increase the area size. Sometimes dithering (subtle noise) helps, but CSS gradients don't offer built-in dithering—use an image or SVG filter as a workaround.

Should I use gradients or images for backgrounds?

Gradients are preferable: smaller file size, scalable to any resolution, and faster rendering. Use images only for complex patterns (textures, patterns) or when a gradient can't achieve the look you need.