Gradient Generator
Create CSS linear and radial gradients with a visual editor.
Reviewed by Aygul Dovletova · Last reviewed
background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
Using the Gradient Generator
- Pick two colors from the color pickers. These become the start and end stops; the browser interpolates every pixel in between in the sRGB color space by default.
- Choose the gradient type - linear for directional color washes, radial for center-outward glows and spotlights.
- Set the angle (linear only).
0degfades from bottom to top,90degfrom left to right,180degfrom top to bottom. This matches the CSS Images Level 3 convention where angles rotate clockwise from the top. - Review the live preview. The swatch shows the exact pixels the browser will paint - no hidden post-processing.
- Click "Copy CSS" to paste the
background-imagedeclaration into any stylesheet, Tailwind arbitrary value, or CSS-in-JS object.
What a CSS gradient actually is
A CSS gradient is not an image file - it's a generated <image> value produced by the linear-gradient() or radial-gradient() functions defined in the CSS Images Module Level 3 specification. The browser resolves these functions at paint time, sampling the interpolated color for every pixel inside the background painting area. Because nothing is rasterized to a file, gradients scale losslessly from a 24px favicon to a 4K hero background without pixelation.
Under the hood, compositors like Chrome's Skia, Firefox's WebRender, and Safari's Core Animation upload gradient stops as a short texture strip and stretch it across the element's background-positioning area. That's why gradients remain cheap even when they cover the whole viewport - the GPU does a single shader pass, not a per-pixel CPU calculation. Interpolation follows the sRGB color space unless you opt into in oklch or in lab (Chrome 111+, Safari 16.2+), which avoids the muddy gray midpoint you get when fading from blue to yellow in sRGB.
When you would reach for a gradient
- Hero section backgrounds that need depth without the weight of a JPEG.
- Button and CTA fills where a subtle two-stop gradient reads as more tactile than flat color.
- Skeleton loaders using a diagonal gradient animated with
background-positionfor a shimmer sweep. - Glassmorphism cards layered over a colorful gradient backdrop with
backdrop-filter: blur(). - Chart fills when you want a bar to fade from high-saturation at the baseline to low-saturation at the tip.
- SVG fallbacks - a gradient used as a mask or a
border-imagesource avoids shipping yet another asset through the network.
Pitfalls that surprise people
- The "gray middle" problem. A red-to-green sRGB gradient passes through muddy olive. Switch to
linear-gradient(in oklch, red, green)for a perceptually even ramp - but check caniuse.com/css-color-4 because older Safari builds fall back to sRGB. - Banding on 8-bit displays. Very subtle two-stop gradients over large areas can show diagonal stripes. Adding a tiny
background-blend-mode: overlaynoise texture, or usingfilter: contrast(1.005), breaks the bands. - Angle direction confusion. CSS angles start at 12 o'clock and rotate clockwise. Designers coming from Sketch or Figma expect 0deg at 3 o'clock - always verify in the preview.
- Hard stops vs smooth ramps.
linear-gradient(red 50%, blue 50%)produces a crisp split, not a fade. Useful for two-tone buttons; surprising if you forget the percentages. - Repeating gradients tiling unexpectedly.
repeating-linear-gradientneeds a fixed-length final stop (like20px), not a percentage, or it fills the whole element as a single cycle.
A bit of background on the spec
CSS gradients entered the platform as proprietary WebKit syntax around 2008 and were standardized in CSS Images Module Level 3. The current grammar supports any number of color stops, percentage or length positions, to keyword directions (to bottom right), conic gradients for pie-chart effects, and the Level 4 in <color-space> hint for perceptual interpolation. Support for linear and radial gradients has been universal since IE10 and Android 4.4, so you can use them without any prefix or fallback on today's web. Conic gradients need Firefox 83+ and were the last holdout. For accessibility, gradients are treated as decorative backgrounds by screen readers - they never expose stop colors, so always ensure foreground text keeps at least WCAG AA 4.5:1 contrast against the darkest point of the gradient underneath.
Gradients vs alternatives
Compared to an exported PNG or JPEG background, a CSS gradient saves a network request, scales perfectly at every DPR, and is trivially themeable with CSS custom properties. Compared to SVG <linearGradient>, the CSS version loses out on mid-stop transforms and complex gradient meshes but wins on terseness - one line versus a whole <defs> block. Compared to Tailwind's bg-gradient-to-r from-x to-y utilities, handwritten gradients let you use custom angles and more than two stops without escaping arbitrary values. For animated gradients, CSS still can't interpolate stops directly in a @keyframes block - you have to animate background-position on a larger-than-viewport gradient, or fall back to Houdini's Paint API for per-frame color math. If you need a true gradient animation with per-stop control, SVG + SMIL or WebGL will beat CSS every time.
Frequently Asked Questions
Why does a red-to-green gradient look muddy in the middle?
By default, CSS interpolates colors in the sRGB color space linearly on each RGB channel. Red (255, 0, 0) and green (0, 128, 0) meet at roughly (128, 64, 0), which the eye reads as dull brown. Switch to <code>linear-gradient(in oklch, red, green)</code> on Chrome 111+ or Safari 16.2+ to get a perceptually uniform fade through yellow, or pick a midpoint color manually and use three stops.
What is the difference between linear-gradient and radial-gradient?
Linear gradients transition along a straight vector defined by an angle or a <code>to <side></code> keyword - every pixel on a line perpendicular to that vector is the same color. Radial gradients transition outward from a focal point in concentric ellipses or circles, which is why they feel like lighting effects. Use linear for directional washes and backgrounds, radial for vignettes, spotlights, and soft highlights on buttons.
Can I add more than two color stops?
Yes - CSS gradients support an arbitrary number of stops, each with an optional position. The syntax is <code>linear-gradient(90deg, red 0%, orange 50%, yellow 100%)</code>. This tool ships with two stops to keep the UI focused; to layer more stops, paste the generated CSS and add them manually. The browser has no hard limit, but past about 10 stops you should probably be using SVG.
How do I animate a CSS gradient?
CSS cannot directly interpolate <code>background-image</code> values in a <code>@keyframes</code> rule - transitioning between two gradient functions produces a jarring cross-fade. The idiomatic workaround is to set a gradient larger than the element (like <code>background-size: 200% 200%</code>) and animate <code>background-position</code> for a sweep effect. For true stop-color animation, CSS Houdini's Paint API or SVG <code><animate></code> are your real options.
Does this tool upload my color choices anywhere?
No. The generator reads the color pickers via the HTML <code><input type="color"></code> widget, computes the gradient string entirely in a Preact component running in your browser, and renders the preview with a plain <code>style</code> attribute. There is no <code>fetch()</code> call, no form post, no analytics on the color values.
What angle should I use for a "top to bottom" gradient?
Use <code>180deg</code>, or the keyword form <code>to bottom</code>. CSS gradient angles start at 12 o'clock and rotate clockwise, so <code>0deg</code> fades from bottom to top, <code>90deg</code> from left to right, and <code>270deg</code> from right to left. This differs from the trigonometric convention and from Figma's rotation handle - always verify against the live preview before shipping.
Why do conic gradients have worse browser support than linear ones?
Conic gradients (<code>conic-gradient()</code>) were specified years after linear and radial, and Firefox only shipped them in version 83 (October 2020). Today every evergreen browser supports them, but if your analytics show meaningful traffic from older Samsung Internet, UC Browser, or outdated WebViews, you may still want a linear fallback via <code>@supports (background: conic-gradient(red, blue))</code>.
Can I use CSS variables inside the generated gradient?
Yes, and it is how most design systems theme gradients. Replace the hard-coded hex values with <code>var(--brand-start)</code> and <code>var(--brand-end)</code> after pasting the CSS. Variables resolve at paint time, so swapping them via <code>document.documentElement.style.setProperty</code> or a dark-mode class repaints the gradient without rebuilding the string.
More CSS & Design
Aspect Ratio Calculator
Calculate and visualize aspect ratios for any dimensions.
Open toolBlob Shape Generator
Generate organic blob shapes as SVG.
Open toolBorder Radius Generator
Create CSS border-radius with a visual corner editor.
Open toolCSS Box Shadow Generator
Create CSS box shadows with a visual editor. CSS box-shadow generator, shadow maker and box-shadow builder with live preview, multi-layer support and Material elevation presets.
Open toolColor Palette Generator
Generate harmonious color palettes, Tailwind-style 50-900 scales and design-system tokens from any base hex color. Also a hex color palette generator (Farbpalette Generator auf Deutsch).
Open toolColor Picker
Pick colors visually and get HEX, RGB, and HSL values.
Open tool