CSS Gradient Generator

Create custom linear and repeating CSS gradients visually with live preview, angle controls, and instant copy-ready CSS code in your browser.

CSS Gradients & The W3C Image Module Specification

In modern web design, CSS gradients belong to the <image> data type governed by the W3C CSS Images Module Level 3 & Level 4. Rather than downloading external raster assets (like JPEG or PNG) that introduce network roundtrips and resolution scaling artifacts, CSS gradients are generated procedurally by the browser's graphics rendering pipeline.

Because they are vector-based mathematical descriptions, CSS gradients render with infinite fidelity across all display resolutions (from standard 96 DPI monitors to 400+ PPI high-density mobile screens) with zero asset transfer overhead. They can be applied anywhere an image is accepted in CSS: background-image, border-image, mask-image, and text clipping fills.

Linear Gradient Geometry & Angle Trigonometry

A linear gradient creates a smooth progression of color along an imaginary gradient line. The direction of this line can be declared using explicit angles (such as 90deg) or directional keywords (such as to right bottom).

The CSS Angle Convention vs. Traditional Mathematics

A frequent point of confusion for engineers is that CSS gradient angles do not follow standard Cartesian trigonometry:

  • In standard trigonometry: 0° points East along the positive X-axis, and angles increase counter-clockwise (North is 90°).
  • In CSS Gradients:0deg points strictly North (straight up, equivalent to to top), and angles increase clockwise:
    • 0deg: Bottom to Top (North)
    • 90deg: Left to Right (East)
    • 180deg: Top to Bottom (South, the default if angle is omitted)
    • 270deg: Right to Left (West)

Directional Keywords & Aspect Ratio Compensation

When using directional keywords like to bottom right, the browser calculates the gradient line so that it is mathematically perpendicular to the line connecting opposite corners. This guarantees that color stops hit the exact extreme corners of the bounding box, regardless of whether the container is square or an extreme landscape rectangle.

Color Stops, Midpoint Hints & Hard-Stripe Techniques

The power of CSS gradients lies in how color stops and transitions are parameterized along the gradient line:

1. Explicit Positions (Lengths & Percentages)

Color stops are defined by a color value followed by an optional position (e.g., linear-gradient(90deg, #3b82f6 0%, #10b981 100%)). The browser interpolates colors linearly between these boundaries. If stop positions are omitted, the browser spaces them equidistantly along the line.

2. Transition Hints (Easing the Midpoint)

By default, the midpoint (50% blend) between two colors occurs exactly halfway between their positions. You can alter this curve by inserting a standalone percentage between stops:

/* Shift the 50% color mix point to 25% along the line */
background: linear-gradient(90deg, #3b82f6, 25%, #10b981);

3. Double Color Stops & Crisp Hard Stripes

Placing two color stops at the exact same position (or using CSS Images Level 4 double stop syntax) eliminates interpolation, creating sharp, razor-clean graphic bands without blur:

/* Crisp 50/50 dual-color split */
background: linear-gradient(90deg, #3b82f6 0% 50%, #10b981 50% 100%);

The Gray Dead Zone: Modern Color Space Interpolation

Have you ever blended two vibrant colors—like cyan and red, or royal blue and sunny yellow—only to notice a dull, muddy, grayish band right in the middle of the transition?

Why Legacy sRGB Interpolation Fails

Historically, all browser gradients interpolated colors inside the standard sRGB color space. In sRGB, colors are mapped to Cartesian coordinates (R, G, B). When interpolating between two complementary hues, the straight line connecting their coordinates passes directly through the low-saturation center where R ≈ G ≈ B, creating the infamous"gray dead zone".

The Modern Solution: CSS Color Module Level 4 (OKLCH & OKLab)

The CSS Images Level 4 specification introduces color space interpolation hints via the in <color-space> syntax. By interpolating in perceptually uniform polar color spaces like OKLCH, the browser preserves perceived chroma (vibrancy) and lightness smoothly across the hue ring:

/* Muddy middle in sRGB */
background: linear-gradient(to right, #00ffff, #ff0077);

/* Luminous, vibrant transition in OKLCH */
background: linear-gradient(in oklch to right, #00ffff, #ff0077);

In OKLCH, hue is treated as a radial angle on a cylinder, avoiding the desaturated axis and producing transitions that match human visual perception.

Radial & Conic Gradients: 2D & Angular Space

Beyond linear progressions, modern CSS provides two additional gradient functions for multi-dimensional visual effects:

Radial Gradients (radial-gradient)

Radial gradients radiate outward from an origin point like ripples in water. The syntax accepts shape (circle or ellipse), sizing constraints (closest-side, farthest-side, closest-corner, farthest-corner), and an origin position (e.g., at 50% 50% or at top right):

/* Atmospheric spotlight glow */
background: radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.4) 0%, transparent 70%);

Conic Gradients (conic-gradient)

Conic gradients rotate color stops around a center point, similar to hands sweeping around a clock face. Unlike radial gradients where color radiates outward from center to edge, conic gradients maintain constant color along any radial line:

/* 360-degree rainbow color wheel / spinner border */
background: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red);

Conic gradients are frequently used to build pie charts, data donut visualizations, iridescent borders, and spinning loading indicators without external SVG assets.

High-Impact Production Patterns & Best Practices

1. Luminous Gradient Text

To apply a vibrant gradient to typography without clipping issues:

.gradient-text {
  background-image: linear-gradient(135deg, #6366f1 0%, #ec4899 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
}

2. Layered Multi-Gradient Mesh Backdrops

Because the background-image property accepts multiple comma-separated image sources, you can layer several translucent radial gradients over a solid base color to construct rich, organic mesh backdrops:

.mesh-background {
  background-color: #0f172a;
  background-image:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.25) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(236, 72, 153, 0.2) 0px, transparent 50%);
}

3. Repeating Gradients & Algorithmic Patterns

CSS provides repeating variants: repeating-linear-gradient andrepeating-radial-gradient. These tile continuously across the container based on the distance between the first and last color stop:

/* Diagonal warning / caution stripes */
.stripe-pattern {
  background: repeating-linear-gradient(
    45deg,
    #1e293b,
    #1e293b 10px,
    #0f172a 10px,
    #0f172a 20px
  );
}

Rendering Pipeline & Animation Performance

Can You Animate CSS Gradients?

Historically, CSS gradients were treated as discrete image files, meaning browsers could not smoothly interpolate between two completely different linear-gradient() declarations in a CSS transition. If you tried animating from a blue gradient to a red gradient, the browser would simply produce an abrupt flash.

High-Performance Animation Strategies

  • 1. Translating Pre-Sized Backgrounds: Set background-size: 200% 200% and animate background-position across keyframes. This shifts the rasterized gradient map across the viewport without generating new geometry each frame.
  • 2. Cross-Fading Overlapping Layers: Place the secondary gradient inside an absolute ::before pseudo-element and animate its opacity. Because opacity is handled natively by the GPU compositor thread, this runs at 60–120 FPS without CPU main-thread overhead.
  • 3. Modern CSS Custom Properties with @property: With modern browser support for the CSS Houdini Properties and Values API, you can register custom angle and color variables (e.g., @property --gradient-angle) with strict types (syntax: '<angle>'). This allows the browser engine to mathematically interpolate the angle directly in a keyframe animation!

Practical Real-World Use Cases

  • Design a landing-page hero background: Blend brand colors across a custom angle to create a smooth linear or radial background gradient.
  • Style primary call-to-action buttons: Generate a subtle two-stop gradient that gives buttons visual depth without looking dated.
  • Build dark-mode surface treatments: Craft low-contrast, dark color transitions that add atmosphere while keeping foreground white text crisp.
  • Create image overlay scrims: Generate a transparent-to-dark gradient to place over hero photographs so overlaid headings remain legible.
  • Translate mockup gradients to CSS: Match exact color stops, positions, and angles from a design file and export browser-ready CSS syntax.

Zero Server Upload Guarantee

100% Client-side generation. OmniTools operates entirely within your browser. All gradient calculations, color stop interpolations, and live CSS generation happen natively on your device.

No design inputs, color selections, or generated styles are ever transmitted to or logged on remote servers.

Frequently Asked Questions

How do I create a linear or repeating CSS gradient with custom color stops?

Pick your start and end colors, adjust the angle in degrees (0deg to 360deg), and switch between linear-gradient and repeating-linear-gradient to preview and copy production-ready CSS background rules.

Can I use CSS gradients with transparency and multiple stops?

Yes. Modern browsers support CSS linear, radial, and repeating gradients across all viewports without requiring external raster image assets.