CSS Gradients: The Complete Practical Guide

Updated · 2 min read

Gradients are pure CSS: no images, no extra requests, perfectly sharp on every screen. This guide covers everything you need day to day, with examples you can paste straight into your stylesheet, or build visually in the gradient generator.

Linear gradients

background: linear-gradient(90deg, #ff5f6d, #ffc371);
  • Direction: an angle (0deg points up, 90deg right, 180deg down) or keywords like to right or to bottom left.
  • Stops: as many colors as you like, each with an optional position: #ff5f6d 0%, #ffc371 60%, #fff 100%.

Hard stops (stripes)

Put two stops at the same position and the colors switch instantly instead of blending:

background: linear-gradient(90deg, #0057b7 50%, #ffd700 50%);

Combine this with repeating-linear-gradient() for patterns:

background: repeating-linear-gradient(45deg, #222 0 10px, #333 10px 20px);

Radial gradients

background: radial-gradient(circle at 30% 20%, #ffc371, #ff5f6d 60%, #5b4bff);

Radial gradients spread from a point. Use circle or ellipse for the shape and at x y for the center. A soft radial glow behind a hero section is an easy way to add depth.

Conic gradients

background: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red);
border-radius: 50%;

Conic gradients sweep around a center like the hands of a clock, which makes them perfect for color wheels and pie charts:

background: conic-gradient(#5b4bff 0 40%, #ff5fb8 40% 75%, #ffc94d 75%);

Smoother blends with OKLCH

Blending two saturated, opposite colors in the default sRGB space often creates a dull gray band in the middle. Modern browsers let you choose the interpolation space:

background: linear-gradient(in oklch, #0000ff, #ffff00);

For older browsers, the simple fix is to add a middle stop yourself, for example a vivid green between blue and yellow.

Gradient text

.gradient-text {
  background: linear-gradient(90deg, #ff5f6d, #ffc371);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

Check contrast on both ends of the gradient: the lightest part must still be readable against the page background.

Gradient borders

The most flexible technique uses two backgrounds, one clipped to the padding box and one to the border box, so it also works with rounded corners:

.gradient-border {
  border: 3px solid transparent;
  border-radius: 12px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(90deg, #5b4bff, #ff5fb8) border-box;
}

Animated gradients

.animated {
  background: linear-gradient(270deg, #5b4bff, #ff5fb8, #ffc94d);
  background-size: 300% 300%;
  animation: shift 8s ease infinite;
}
@keyframes shift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

Respect users who prefer less motion by disabling the animation inside @media (prefers-reduced-motion: reduce).

Gradients in Tailwind CSS

Tailwind has utilities for simple linear gradients, such as bg-gradient-to-r from-indigo-500 to-pink-500 (v3), renamed bg-linear-to-r in v4. For anything more complex, use an arbitrary value. The gradient generator outputs one for you, like bg-[linear-gradient(135deg,#ff5f6d_0%,#ffc371_100%)].

Where to get good gradient colors

  • Start from a photo: extract its colors with Palette from Image.
  • Use neighbours on the color wheel (analogous colors) for smooth, natural blends; every color page lists them.
  • Browse the presets in the gradient generator and tweak from there.

Tools used in this guide

More guides