Everything about CSS gradients — linear, radial, conic. Syntax, examples, Tailwind classes, performance tips, and a free visual generator.
🌈 Open CSS Gradient GeneratorFree · No signup · 24 presets · Tailwind output · PNG export
CSS gradients are one of the most powerful tools in a developer's design toolkit. They replace background images with zero HTTP requests, deliver perfect resolution on retina and 4K displays, and take a single line of CSS. The CSS Gradient Generator on ToolForge lets you create any gradient visually — drag color stops, switch gradient types, choose from 24 presets, and copy the result as standard CSS or Tailwind classes in one click.
This guide covers everything: the syntax for all three gradient types (linear, radial, conic), color stop positioning, Tailwind CSS gradient utilities, animation techniques, gradient overlays on images, and 15 ready-to-use patterns. Bookmark it as your gradient reference.
The CSS <gradient> data type is technically a subtype of <image> — not a color. This distinction matters: you can use gradients anywhere an image is accepted (background-image, border-image, mask-image), but not in properties that require a color value like color or border-color.
Gradients replaced background images because they offer four decisive advantages: resolution independence (infinitely scalable, no pixelation), zero HTTP requests (drawn by the browser's rendering engine), GPU acceleration (rendered in compositing, not the paint layer), and instant editability (change a hex code in one file vs. re-exporting an asset from Photoshop).
Browser support is universal. Linear and radial gradients work in every browser since 2012. Conic gradients, the newest addition, are supported in Chrome 69+, Firefox 83+, Safari 12.1+, and Edge 79+ — over 96% of global usage as of 2026. No vendor prefixes needed.
background: linear-gradient(direction, color-stop1, color-stop2, ...);
The direction can be a keyword (to right, to bottom left) or a degree value. If omitted, the default is to bottom (180deg, top to bottom).
| Keyword | Degree | Direction |
|---|---|---|
| to top | 0deg | Bottom → Top |
| to right | 90deg | Left → Right |
| to bottom | 180deg | Top → Bottom (default) |
| to left | 270deg | Right → Left |
| to bottom right | ~135deg | Top-left → Bottom-right |
| to bottom left | ~225deg | Top-right → Bottom-left |
Degree wheel note: 0° points up (to top), 90° points right (to right), 180° points down (to bottom), 270° points left (to left). Degrees increase clockwise.
Color stops define where each color starts and ends. Without explicit positions, stops are evenly distributed. With positions (in %, px, or other length units), you control exactly where each transition happens.
Two colors — evenly split
background: linear-gradient(to right, red, blue);
Three colors — equal thirds
background: linear-gradient(to right, red, yellow, blue);
Uneven stop — more red area
background: linear-gradient(to right, red 0%, yellow 20%, green 100%);
Hard stop — no transition (stripes)
background: linear-gradient(to right, red 50%, blue 50%);
1. Simple horizontal (left to right)
background: linear-gradient(to right, #2193b0, #6dd5ed);
2. Three-color diagonal (sunset)
background: linear-gradient(135deg, #f12711 0%, #f5af19 100%);
3. Multi-stop neon
background: linear-gradient(90deg, #f64f59 0%, #c471ed 50%, #12c2e9 100%);
4. Hard-stop stripe pattern
background: linear-gradient(to right, #667eea 50%, #764ba2 50%);
5. Transparent overlay (use over an image)
background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.8));
6. Gradient border (using border-image)
border: 3px solid; border-image: linear-gradient(to right, #667eea, #764ba2) 1;
background: radial-gradient(shape size at position, color-stop1, color-stop2, ...);
Shape: circle gives equal radius in all directions. ellipse (default) stretches to fill the element dimensions.
Size keywords: farthest-corner (default) extends to the furthest corner. closest-side ends at the nearest edge. farthest-side ends at the farthest edge.
Position: at center (default), at top left, or precise percentages like at 30% 70%.
1. Spotlight effect (white center, dark edges)
background: radial-gradient(circle at center, #ffffff, #1a1a2e);
2. Vignette overlay (transparent center, dark edges)
background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.7) 100%);
3. Glowing orb
background: radial-gradient(circle at center, #667eea 0%, #764ba2 50%, #0f0c29 100%);
background: conic-gradient(from angle at position, color-stop1, color-stop2, ...);
Conic gradients rotate colors around a center point — think of a color wheel or the sweep of a clock hand. Unlike linear and radial gradients where stops use distance, conic stops use angle positions (in degrees or percentages).
Use cases: Pie charts (hard color stops), color wheels (smooth transitions), circular progress indicators, decorative angular patterns.
Browser support: Chrome 69+, Firefox 83+, Safari 12.1+, Edge 79+. Covers over 95% of global usage as of 2026. Always provide a fallback background color for unsupported browsers.
1. Simple color wheel
background: conic-gradient(red, yellow, green, blue, red);
2. Pie chart (35% / 30% / 35%)
background: conic-gradient(#4f46e5 0% 35%, #10b981 35% 65%, #f59e0b 65% 100%); border-radius: 50%;
3. Angular gradient (starburst effect)
background: conic-gradient(from 45deg, #667eea, #764ba2, #667eea);
CSS provides repeating variants of all three gradient types: repeating-linear-gradient(), repeating-radial-gradient(), and repeating-conic-gradient(). The pattern defined between the first and last stop is tiled infinitely. This makes stripes, patterns, and decorative backgrounds easy to create without JavaScript or image assets.
/* Diagonal stripes */ background: repeating-linear-gradient( 45deg, #606dbc, #606dbc 10px, #465298 10px, #465298 20px ); /* Repeating radial rings */ background: repeating-radial-gradient( circle at center, #667eea 0px, #667eea 5px, transparent 5px, transparent 20px );
Key rule: the last color stop position defines the pattern tile size. In the diagonal stripe example, the pattern repeats every 20px.
Tailwind includes a set of gradient direction utilities combined with color stop utilities. You can combine any direction with any color stop from the Tailwind palette.
<!-- Directions -->
bg-gradient-to-t (to top)
bg-gradient-to-tr (to top right)
bg-gradient-to-r (to right)
bg-gradient-to-br (to bottom right)
bg-gradient-to-b (to bottom)
bg-gradient-to-bl (to bottom left)
bg-gradient-to-l (to left)
bg-gradient-to-tl (to top left)
<!-- 2-stop gradient -->
<div class="bg-gradient-to-r from-cyan-500 to-blue-500">
<!-- 3-stop gradient with via -->
<div class="bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500">
<!-- Tailwind palette colors -->
from-{color}-{shade} via-{color}-{shade} to-{color}-{shade}For gradients with custom angles, more than 3 stops, or specific hex colors not in the Tailwind palette, use arbitrary values. Spaces become underscores, commas remain as-is:
<!-- Custom angle with hex colors --> <div class="bg-[linear-gradient(135deg,#667eea_0%,#764ba2_100%)]"> <!-- Radial gradient --> <div class="bg-[radial-gradient(circle_at_center,#667eea,#0f0c29)]"> <!-- Conic gradient --> <div class="bg-[conic-gradient(from_0deg,red,blue,red)]">
<span class="bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent"> Gradient Text </span>
Generate any gradient and copy the Tailwind class from our CSS Gradient Generator. It automatically outputs the correct Tailwind arbitrary value syntax for any combination of stops and angles.
A gradient overlay on an image creates visual depth and ensures text legibility on photo backgrounds. The technique uses the background-image shorthand to layer a gradient on top of an image URL. The gradient must be listed first to render on top.
/* Standard CSS — gradient layer over image */
background-image:
linear-gradient(rgba(0,0,0,0.2), rgba(0,0,0,0.8)),
url('/hero-image.jpg');
background-size: cover;
background-position: center;
/* Tailwind approach — use a positioned overlay div */
<div class="relative">
<img src="/hero-image.jpg" class="w-full h-64 object-cover" alt="">
<div class="absolute inset-0 bg-gradient-to-b from-transparent to-black/80"></div>
<h1 class="absolute bottom-4 left-4 text-white font-bold">Title</h1>
</div>Verify text contrast against your gradient using our Color Contrast Checker to meet WCAG accessibility standards.
CSS cannot directly animate between two gradient values — gradients are treated as images, not interpolatable properties. The two standard workarounds are background-position animation on an oversized gradient, and opacity animation on stacked pseudo-elements.
.animated-gradient {
background: linear-gradient(270deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
background-size: 400% 400%;
animation: gradientShift 8s ease infinite;
}
@keyframes gradientShift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}.element { position: relative; }
.element::before, .element::after {
content: '';
position: absolute; inset: 0;
transition: opacity 2s ease;
}
.element::before { background: linear-gradient(135deg, #667eea, #764ba2); }
.element::after { background: linear-gradient(135deg, #f12711, #f5af19); opacity: 0; }
.element:hover::before { opacity: 0; }
.element:hover::after { opacity: 1; }Performance note: Animating background-position triggers paint repaint on each frame. For critical UI, use the pseudo-element approach with opacity — which is GPU-composited and paint-free. Avoid animated gradients near scrolling content or for elements that update at 60fps.
All 24 presets are available in our CSS Gradient Generator — click any to load and customize. Here are 15 to copy directly:
| Name | CSS | Best For |
|---|---|---|
| Sunset | linear-gradient(to right, #f12711, #f5af19) | Hero sections |
| Ocean | linear-gradient(to right, #2193b0, #6dd5ed) | Headers |
| Forest | linear-gradient(to bottom, #134e5e, #71b280) | Cards |
| Midnight | linear-gradient(to bottom, #0f0c29, #302b63, #24243e) | Dark backgrounds |
| Neon Purple | linear-gradient(135deg, #667eea, #764ba2) | CTAs, buttons |
| Fire | linear-gradient(to right, #f83600, #f9d423) | Alerts, warnings |
| Spring | linear-gradient(135deg, #93f9b9, #1d976c) | Success states |
| Candy | linear-gradient(135deg, #f64f59, #c471ed, #12c2e9) | Playful UI |
| Lavender | linear-gradient(135deg, #e0c3fc, #8ec5fc) | Soft backgrounds |
| Gold Rush | linear-gradient(135deg, #f7971e, #ffd200) | Premium feel |
| Charcoal | linear-gradient(135deg, #485563, #29323c) | Dark UI cards |
| Electric | linear-gradient(to right, #4776e6, #8e54e9) | Tech products |
| Cosmic | linear-gradient(135deg, #ff0099, #493240) | Bold CTAs |
| Spotlight | radial-gradient(circle at center, #fff, #1a1a2e) | Modal overlays |
| Color Wheel | conic-gradient(red,yellow,green,blue,red) | Decorative elements |
CSS gradients are GPU-accelerated and render in the compositing layer — they are faster than equivalent background images on every modern browser.
Gradients are invisible to screen readers — they are background images, not content. Never use gradient text as the only way to convey information.
For text on gradient backgrounds, verify contrast using the Color Contrast Checker tool. Both the lightest and darkest parts of the gradient must meet WCAG 2.1 AA (4.5:1 for normal text).
Avoid rapidly flashing animated gradients (>3 flashes per second) — this can trigger photosensitive seizures (WCAG 2.3.1 Three Flashes).
CSS gradients are print-friendly — they render in print stylesheets. Background images with background: url() are hidden by default in print. Use @media print and background-color: as a fallback if the gradient conveys meaning.
In high-contrast mode (Windows forced colors), gradients are replaced with solid colors. Do not rely on gradients for UI affordances like buttons — use borders and text too.
Use the CSS Gradient Generator to build any gradient visually. Choose from 24 presets, drag color stops, customize the angle, and copy as standard CSS or Tailwind classes. Export as PNG or SVG too.
Open CSS Gradient GeneratorColor Contrast Checker
Verify WCAG contrast ratios for text on gradient backgrounds
CSS Box Shadow Generator
Create multi-layer box shadows with live preview
Color Picker
Pick colors in HEX, RGB, HSL — perfect for gradient color stops
Meta Tag Generator
Generate SEO and Open Graph meta tags for your pages