CSS Gradient Generator: Complete Guide to Linear and Radial Gradients

Master CSS gradients: linear, radial, and conic. Learn syntax, color stops, angles, and creative techniques for backgrounds, buttons, and UI elements.

6 min read CSS · Design · Backgrounds 6 sections + FAQ

CSS gradients are one of the most powerful visual tools available to web designers — they create smooth transitions between colors without a single image file, render at any resolution, and animate with CSS transitions. Yet many designers only use the basics: two colors, one direction.

This guide covers the full range of CSS gradient capabilities: the three gradient types, advanced color stops, angle notation, and creative techniques like mesh gradients, gradient text, and striped backgrounds — plus performance considerations and best practices.

CSS gradient types overview

CSS provides three gradient functions. linear-gradient() creates a transition along a straight line, defined by a direction or angle. radial-gradient() creates a transition that radiates outward from a central point, in a circle or ellipse. conic-gradient() creates a transition that sweeps around a central point like a color wheel or pie chart. All three are used as values for the background-image property (and can be combined with other background layers using commas). They are not images but CSS-generated values, which means they can be animated with @property (CSS Houdini) and respond to color scheme preferences with prefers-color-scheme.

Free Tool CSS Gradient Generator Create linear and radial gradients with live preview and copy-ready CSS

linear-gradient syntax and angles

The basic syntax is linear-gradient(direction, color-stop-1, color-stop-2, ...). Direction can be a keyword (to bottom, to right, to bottom right) or an angle in degrees (0deg = upward, 90deg = rightward, 180deg = downward). The angle system uses compass-style measurement: 0deg points up (12 o'clock), increasing clockwise. Common directions: to bottom = 180deg, to right = 90deg, to top right = 315deg. You can also use turns (0.25turn = 90deg) or radians.

/* Equivalent declarations */
background: linear-gradient(to bottom, #3A7BD5, #00D2FF);
background: linear-gradient(180deg, #3A7BD5, #00D2FF);

/* Diagonal */
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

/* Multi-stop */
background: linear-gradient(
  to right,
  #f093fb 0%,
  #f5576c 50%,
  #4facfe 100%
);

Color stops and transitions

Color stops define where each color starts and ends within the gradient. Without explicit positions, colors are evenly distributed. With positions, you control the exact location: a percentage (0–100%), a length (px, rem, em), or a calc() expression. Two adjacent stops at the same position create a hard edge (no transition) — useful for striped backgrounds. A color hint (a single value between two stops) shifts the midpoint of the transition: background: linear-gradient(red, 30%, blue) makes the transition start later, compressing the red zone.

/* Hard stops — stripes */
background: linear-gradient(
  to right,
  #e74c3c 0% 33%,
  #3498db 33% 66%,
  #2ecc71 66% 100%
);

/* Color hint — non-linear transition */
background: linear-gradient(
  to right,
  #3A7BD5,
  20%,
  #00D2FF
);

/* Transparent fade */
background: linear-gradient(
  to bottom,
  rgba(0,0,0,0),
  rgba(0,0,0,0.8)
);
Free Tool Color Palette Generator Find harmonious color pairs for your gradients

radial-gradient and conic-gradient

radial-gradient() radiates from a center point. The syntax: radial-gradient(shape size at position, colors). Shape: circle or ellipse (default). Size: closest-side, farthest-corner, etc. Position: same as background-position (center, top right, 50% 30%). conic-gradient() sweeps around a center point: colors are distributed around 360°. Useful for pie charts, color wheels, and rotational patterns. The from keyword sets the starting angle: conic-gradient(from 45deg, red, yellow, green). Repeating variants (repeating-linear-gradient, repeating-radial-gradient, repeating-conic-gradient) tile the gradient pattern.

/* Radial spotlight */
background: radial-gradient(
  circle at center,
  #3A7BD5 0%,
  transparent 70%
);

/* Conic — color wheel */
background: conic-gradient(
  red, yellow, lime, cyan, blue, magenta, red
);

/* Repeating stripes */
background: repeating-linear-gradient(
  45deg,
  transparent,
  transparent 10px,
  rgba(0,0,0,0.1) 10px,
  rgba(0,0,0,0.1) 20px
);

Creative gradient techniques

Gradient text: apply a gradient to background-image, then use background-clip: text and -webkit-background-clip: text with color: transparent. This clips the gradient to the text shape. Gradient borders: use background with padding-box and border-box clipping, or the border-image property with a gradient value. Mesh gradients: layer multiple radial gradients with different positions and colors. Use a container with background: multiple gradients separated by commas — each can have different size, position, and blend. Noise texture overlay: combine a CSS gradient with an SVG filter or a semi-transparent noise image to add organic texture. Dark-mode adaptive gradients: use CSS custom properties inside gradient functions so the gradient adapts when the theme changes.

Performance and best practices

CSS gradients are GPU-composited and perform well in most cases. However, very complex gradients (many stops, large areas, animated gradients) can cause repaints. Avoid animating gradients with CSS transitions on background-image — browsers cannot interpolate between gradients natively. Instead, animate with @property (CSS Houdini) which can register typed custom properties. For large gradient areas (full-page backgrounds), using will-change: background or promoting the element to a compositing layer can improve scroll performance. Always test gradient accessibility: text over gradient backgrounds must maintain WCAG contrast at every point of the gradient, not just the average.

Free Tool HEX to RGB Converter Convert gradient colors between HEX and RGB formats

Frequently Asked Questions

What is a CSS gradient? +
A CSS gradient is a programmatically generated transition between two or more colors, defined entirely in CSS without image files. There are three types: linear-gradient() (straight line), radial-gradient() (radiating from a point), and conic-gradient() (sweeping around a center). They are used as values for background-image.
How do I create a linear gradient in CSS? +
Use linear-gradient(direction, color1, color2, ...). Direction can be a keyword (to right, to bottom) or an angle in degrees (90deg = rightward, 180deg = downward). Example: background: linear-gradient(135deg, #667eea, #764ba2) creates a diagonal purple gradient.
What is the difference between linear-gradient and radial-gradient? +
linear-gradient() transitions colors along a straight line from one side/angle to another. radial-gradient() radiates outward from a center point, creating circular or elliptical patterns. Use linear for directional effects (side lighting, depth) and radial for spotlight effects, glowing centers, or organic color blends.
How do I create hard color stops in CSS gradients? +
Place two adjacent color stops at the same percentage position. For example: linear-gradient(to right, red 0% 50%, blue 50% 100%) creates a sharp split with no transition — exactly half red, half blue. This technique is used for striped patterns, flags, and hard-edged color sections.
Can I animate CSS gradients? +
CSS transitions cannot interpolate between gradient values on background-image because the browser treats them as different types, not numeric values. The workaround is to use CSS @property (Houdini) to register custom properties with a type, then use those variables inside your gradient and animate them. This works in Chrome/Edge and is progressively supported in Firefox/Safari.
How do I create gradient text in CSS? +
Apply the gradient to background-image, then use background-clip: text (with -webkit-background-clip: text for compatibility) and set color: transparent. Example: .text { background-image: linear-gradient(90deg, #f093fb, #f5576c); -webkit-background-clip: text; background-clip: text; color: transparent; }
Does the PixCode gradient generator support all gradient types? +
The PixCode Gradient Generator supports linear and radial gradients with multiple color stops, adjustable angles, and live preview. It generates copy-ready CSS code. For conic gradients and advanced patterns, the exported CSS can be manually extended with the techniques described in this guide.