CSS Gradients Cheatsheet: Interactive Visual Guide

October 16, 2026  |  Cheatsheet  |  CSS

By Syed · Frontend Engineer & Creator of UITweak

Gradients add color depth without a single image file. The syntax looks cryptic until you see it move, so every section below is interactive: change the type, drag the stops, and copy the CSS.

Prefer building over reading? Open the Mesh Gradient tool →

Interactive gradient builder

When you pick two colors and a stop position, the browser builds a paint shader, not an image: it computes a gradient line from the angle through the center of the border box, places your stops along it as percentages of its length, and interpolates every pixel between them. Colors outside the first and last stops are clamped to the end colors, which is why dragging a stop toward the midpoint compresses the blend into the remaining range. The radial variant draws concentric ellipses from a center point outward, while conic sweeps color angles around a center point like a pie chart, which is why the same two colors produce such different results.

preview

type

.box {
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
}

Gradient syntax

Radial gradients resolve stops against the distance from the center to the ending shape's edge (a circle reaching the farthest corner by default), and conic gradients resolve stops as angles around the center, which is why conic stops are usually written as red 0deg, blue 90deg. The repeating- variants take the final stop position as the period: after the last color the browser restarts the stop list, tiling the pattern across the box with no extra markup.

Click each type to see what it does:

linear-gradient

Blends colors along a straight line. The first value is the direction: an angle like 135deg, or a keyword like to right. Then come color stops. linear-gradient(135deg, #6366f1, #a855f7) is the classic diagonal brand gradient.

/* linear: direction, then color stops */
background: linear-gradient(135deg, #6366f1, #a855f7);

/* radial: shape, then color stops */
background: radial-gradient(circle, #fbbf24, #f97316);

/* conic: sweeps around a center */
background: conic-gradient(from 90deg, #f43f5e, #f59e0b, #10b981, #f43f5e);

/* hard stop: same position twice = sharp line */
background: linear-gradient(90deg, #6366f1 0 40%, #a855f7 60% 100%);

/* repeating stripes */
background: repeating-linear-gradient(45deg, #6366f1 0 12px, transparent 12px 24px);

Tailwind gradient utilities

Tailwind compiles bg-gradient-to-r from-sky-400 to-blue-600 into a background-image that uses CSS variables (--tw-gradient-from, --tw-gradient-to, optional --tw-gradient-via) so each color class sets one variable and the direction class assembles the linear-gradient() from them. Because interpolation still happens in sRGB by default, a midpoint between two Tailwind colors can look muddy; a via- stop pins a color at an exact position the same way hand-written stop percentages do. Arbitrary values like bg-[radial-gradient(circle,#fbbf24,#f97316)] bypass the variable system and emit your raw background-image as-is, parsed exactly as if written in a stylesheet.

bg-gradient-to-r

linear-gradient(to right, ...)

bg-gradient-to-br

linear-gradient(to bottom right, ...)

from-indigo-500

starting color stop

via-purple-500

middle color stop

to-pink-500

ending color stop

bg-[radial-gradient(...)]

arbitrary radial

<!-- diagonal brand gradient -->
<div class="bg-gradient-to-br from-indigo-500 via-purple-500 to-pink-500">
  ...
</div>

<!-- arbitrary radial gradient -->
<div class="bg-[radial-gradient(circle,#fbbf24,#f97316)]">
  ...
</div>

Common recipes

Each recipe composes one gradient declaration with other CSS rather than relying on the gradient alone. The page-background tint uses a full-viewport radial-gradient whose elliptical falloff concentrates color near the top; it sits in background-image on the body, scrolls naturally, and costs no extra layer. Gradient text works by painting the gradient into the element, then making the text transparent and clipping the background to the glyphs with -webkit-background-clip: text; the browser rasterizes the gradient once for the box, then masks it by the text shape. The dark image overlay stacks a transparent-to-black linear gradient in front of an image as multiple backgrounds, needing no extra div and no absolute positioning.

1. Subtle page background

2. Gradient text

Gradient headline

3. Image overlay for readable text

Text stays readable

/* subtle background: barely-there tint fading to neutral */
.hero {
  background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 60%);
}

<!-- gradient text -->
<p class="bg-gradient-to-r from-indigo-600 via-purple-600 to-pink-600 bg-clip-text text-transparent">
  Gradient headline
</p>

/* dark overlay so text reads over any image */
.overlay {
  background: linear-gradient(to top, rgba(0,0,0,0.75), transparent 60%);
}

Want multi-color mesh gradients without writing stops by hand? Try our free Mesh Gradient Generator with live preview and one-click code export.

Common Production Bugs & Fixes

1. Banding on smooth dark gradients

What goes wrong: a slow, dark gradient (for example a near-black hero fade) renders as visible stripes on large screens.

Why: displays quantize each channel to 8 bits, so a gradient spanning a small brightness range across a large area steps in discrete values the eye can detect. The browser interpolates correctly; the banding is quantization at render time.

The fix: add a fine noise overlay so the eye breaks the edges between bands:

.hero {
  position: relative;
  background: linear-gradient(to bottom, #0b1026, #1a2242);
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  pointer-events: none;
}

2. Hard color stops rendering as a soft blend

What goes wrong: you write linear-gradient(red 50%, blue 50%) expecting a hard two-color split and get a smeared edge.

Why: a single stop position still leaves the browser interpolating between the two colors at that point, and anti-aliasing softens it further. Per the spec, a hard edge needs two stops at the same position.

The fix: declare the boundary twice so the interpolation interval has zero width:

.hard-split {
  background: linear-gradient(to right, red 0 50%, blue 50% 100%);
}

Double-position syntax (red 0 50%) pins both edges of the stop, and the browser draws a crisp line at 50% with no blend.

3. Conic gradients pointing the wrong way

What goes wrong: a conic-gradient pie chart starts at the wrong angle, and changing the rotation moves the wrong piece.

Why: conic gradients start at the top and sweep clockwise, and the from keyword plus the at position keyword share a grammar where order matters: conic-gradient(from 45deg at 50% 50%, ...). Swapping them is a parse error, not a visual tweak.

The fix: write the center and starting angle explicitly, and use double-position stops for hard wedges:

.pie {
  background: conic-gradient(from 0deg at 50% 50%, #f59e0b 0 40%, #1e293b 40% 100%);
}

This draws an orange wedge from the top spanning 40% of the circle (0deg to 144deg), then dark slate for the rest. To rotate the chart, change only the from angle.

4. Transparent-to-color gradients going through gray

What goes wrong: linear-gradient(to right, transparent, #f97316) fades through a dull grayish tone before reaching orange.

Why: transparent is shorthand for transparent black (rgb(0 0 0 / 0)), and the browser interpolates premultiplied channels from black to orange, dragging the midpoint toward gray. This is per-spec alpha interpolation, not an error in your colors.

The fix: name the transparent end in the same color as the visible end, or choose an interpolation space that preserves hue:

.fade {
  background: linear-gradient(to right, rgb(249 115 22 / 0), #f97316);
}

/* or, in supporting browsers, interpolate in a perceptual space */
.fade-oklch {
  background: linear-gradient(in oklch to right, transparent, #f97316);
}

The first version fades only the alpha of orange to zero, so the midpoint stays orange. The second interpolates in oklch, which avoids the gray dip for most color pairs.

Real-World Recipes

1. Soft top glow for a dark hero

A centered radial glow near the top of a dark hero creates depth without an image asset. Place a subtle blue-violet ellipse whose far edges dissolve into the background color, positioned with at 50% 0% so the hotspot hugs the top edge. Layer it as the first of two backgrounds so it paints above the flat color, and keep the glow close to the base hue so the blend has no visible seam.

.hero {
  min-height: 90vh;
  background:
    radial-gradient(ellipse 80% 55% at 50% 0%, rgb(99 102 241 / 0.35), transparent 70%),
    #0b1026;
}

2. Gradient headline text that survives older browsers

Gradient text needs a fallback because background-clip: text is still prefixed in some browsers. Set the headline's color to one of the gradient colors as the no-support fallback, then apply the gradient with the prefixed clip and transparent text color. Because the gradient paints across the whole element box, very long headlines compress the color range, so constrain the element's width or adjust background-size to taste.

.headline {
  font-weight: 800;
  color: #f59e0b; /* fallback if background-clip: text is unsupported */
  background-image: linear-gradient(120deg, #f59e0b, #ec4899, #8b5cf6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

3. Diagonal striped loading shimmer

A repeating diagonal stripe animated along its axis is the standard skeleton-screen shimmer. Build the stripes with repeating-linear-gradient at 45deg and a narrow bright band, then animate background-position so the stripes travel. Keep the period constant between the gradient and the animation so the motion loops without a jump.

.skeleton {
  background: repeating-linear-gradient(
    45deg,
    #e2e8f0 0 10px,
    #f1f5f9 10px 20px
  );
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
  to {
    background-position: 28.28px 0; /* one period shifted along the 45deg axis */
  }
}

FAQ

Does a gradient trigger a repaint or a relayout when I animate it?

Gradients are paint, so changing one repaints the element's layer without reflowing layout. Animating background-image itself is expensive because the browser re-rasterizes the shader every frame; animating a cheap proxy like background-position or a custom property registered with @property avoids rebuilding the gradient each frame.

Why does my gradient look different in Chrome and Firefox?

Both follow the same spec, but legacy builds interpolated in different color spaces, and Safari historically gamma-corrected differently. The visible difference almost always comes from the interpolation color space, so pin it explicitly with in srgb, in oklch, or in hsl and the result becomes deterministic.

Can I transition between two different gradients on hover?

Not directly: background-image is not an animatable property, so a transition on it flips instantly at the end of the duration in every browser. The reliable pattern is to stack two absolutely-positioned layers with different gradients and transition the top layer's opacity, which animates cheaply and produces a true crossfade.

How do I make a gradient follow the border-radius of its element?

Gradients paint into the element's background painting area, which border-radius clips automatically during paint, so a gradient on a rounded card already follows the corners. The clipping breaks only when the gradient is painted by a child or pseudo-element that does not inherit the radius; give the child border-radius: inherit or set overflow: hidden on the parent so the same clip applies.

Share this guide