CSS Gradients: Why Your Color Transitions Look Muddy and How to Fix Them

Published: (March 24, 2026 at 10:02 PM EDT)
3 min read
Source: Dev.to

Source: Dev.to

Why Gradients Can Look Muddy

When you create a gradient between two vibrant colors, you might see an unexpected grey band in the middle. This happens because the browser interpolates colors in the default sRGB color space, which follows straight lines through the RGB cube.

For example, the straight line between blue (#0000FF) and yellow (#FFFF00) passes through a midpoint of approximately #808080—a literal grey. The RGB model does not align with human color perception, so perceptually different colors can be close in RGB space, and vice‑versa.

Color Interpolation and Perceptual Color Spaces

To avoid muddy transitions, interpolate colors in a perceptual color space. Modern CSS lets you specify the interpolation space with the in keyword.

/* Muddy transition in sRGB */
.gradient-srgb {
  background: linear-gradient(to right, blue, yellow);
}

/* Vibrant transition in OKLCH */
.gradient-oklch {
  background: linear-gradient(in oklch to right, blue, yellow);
}

The in oklch syntax tells the browser to interpolate in the OKLCH color space, which follows a path through more colorful hues rather than through grey, resulting in a natural‑looking gradient.

CSS Gradient Functions

Linear Gradient

Creates a transition along a straight line.

background: linear-gradient(135deg, #667eea, #764ba2);
  • Angle defines direction: 0deg (bottom‑to‑top), 90deg (left‑to‑right), 135deg (top‑left to bottom‑right).
  • Keywords like to right, to bottom left, etc., can also be used.

Radial Gradient

Transitions outward from a center point.

background: radial-gradient(circle at 30% 50%, #667eea, #764ba2);
  • Shape: circle or ellipse.
  • Position (at 30% 50%) sets the center; default is an ellipse at the element’s center.

Conic Gradient

Transitions around a center point, like a color wheel.

background: conic-gradient(from 0deg at 50% 50%, #667eea, #764ba2, #667eea);

Conic gradients are great for pie charts, color pickers, and radial progress indicators.

Controlling Color Stops

By default, color stops are evenly spaced, but you can position them explicitly.

/* Blue dominates most of the gradient */
background: linear-gradient(
  to right,
  #667eea 0%,
  #667eea 60%,
  #764ba2 100%
);

Hard Edges

Placing two stops at the same position creates a sharp boundary.

/* Sharp color boundary at 50% */
background: linear-gradient(
  to right,
  #667eea 50%,
  #764ba2 50%
);

Midpoint Hints

Use a color hint to shift where the transition’s halfway point occurs.

background: linear-gradient(
  to right,
  #667eea,
  30%,               /* midpoint at 30% instead of 50% */
  #764ba2
);

Adding Intermediate Stops for Depth

Simple two‑color gradients can appear flat. Introducing an intermediate stop adds perceived depth.

/* Flat */
background: linear-gradient(135deg, #667eea, #764ba2);

/* Rich with depth */
background: linear-gradient(
  135deg,
  #667eea 0%,
  #5a67d8 30%,
  #764ba2 100%
);

The intermediate color should be a blend that maintains vibrancy. Selecting it in a perceptual color space (e.g., OKLCH) yields better results than a simple arithmetic average.

0 views
Back to Blog

Related posts

Read more »