Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why your CSS gradient looks muddy in the middle (and the one-line fix)

If you've ever written linear-gradient(blue, yellow) and got a dull grey-ish band in the middle, the colours aren't wrong; the interpolation is. By default browsers blend gradient stops in sRGB, which isn't perceptually even. Halfway between a saturated blue and a saturated yellow in sRGB is a desaturated grey. The fix: interpolate in OKLab or OKLCH Modern CSS lets you choose the colour space the…

Many people have experienced the issue of their CSS gradients appearing muddy in the middle. This occurs when using the `linear-gradient()` function with colors such as blue and yellow, resulting in a dull grey band. The issue is not with the colors themselves, but with the way browsers blend the gradient stops in the default sRGB colour space. Halfway between a saturated blue and a saturated yellow in sRGB, the colour becomes a desaturated grey.

The solution to this problem is to interpolate the colours in a colour space that provides perceptually even blending, such as OKLab or OKLCH. Modern CSS allows developers to choose the colour space for gradient blending. For example, the following code blends the gradient in OKLab, resulting in a perceptually even gradient with no grey band:

`background: linear-gradient(in oklab 90deg, #1e40ff, #ffd400);`

Alternatively, OKLCH can also be used, which interpolates the hue as an angle, resulting in very vivid gradients:

`background: linear-gradient(in oklch 90deg, #1e40ff, #ffd400);`

The OKLab colour space is recommended for most UI gradients as it keeps lightness changing smoothly. However, OKLCH can be used for more vivid hero backgrounds, although it might be too intense for buttons. It's important to note that the `in` colorspace syntax is supported in current versions of Chrome, Edge, Safari, and Firefox. For older browsers, the plain sRGB line should be included first to ensure a fallback.

In addition to using OKLab or OKLCH, there are other small tips to improve gradient gradients. Adding a hand-picked middle stop, such as a green between blue and yellow, can also eliminate the grey band. Conic gradients are ideal for pie-chart style rings and colour wheels, while repeating-linear-gradient() can create stripes without the need for images.

It's also worth noting that transparent stops, while useful, can darken edges due to sRGB blending rules. Using the same colour at 0 alpha (e.g. `rgb(30 64 255 / 0)`) can fade cleanly in these cases.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Serv-U's Critical CVE Cluster Is an Authorization and Patching Problem

Serv-U's Critical CVE Cluster Is an Authorization and Patching Problem SolarWinds Serv-U 2026.3 release notes list a cluster of critical vulnerabilities fixed in the July 21, 2026 release.

  • Critical vulnerabilities rated 9.1 severity allow privilege escalation
  • Majority of issues impact Linux deployments, risking root-level execution
  • Upgrade to patched release, enforce privilege separation and logging

You Can Now Accept or Decline DEV Organization Invitations From Notifications! 🎉

A small but useful improvement to DEV that I'm happy to share! I came across an issue raised by @francistrdev about accepting or declining organization invitations directly from the notifications…

  • Users can accept or decline DEV organization invitations via notifications.
  • Notifications display "Accept" and "Decline" options for invitations.
  • Feature enhancements involved multiple components and recent contributions.

How to Build a Next.js App That's Harder to Break in Penetration Testing 🔐

You ship your Next.js app. It looks great and the Lighthouse score is green. Then a penetration tester sends you a report, and it's longer than your README. It happens to many of us.

  • Keep Next.js and dependencies updated to patch security vulnerabilities.
  • Validate permissions and input on the server side, not just client-side.
  • Add security headers like CSP, HSTS, and Referrer-Policy to tighten app security.

More from Saturday 14 November →