<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Reflected DotCom</title>
    <description>The latest articles on DEV Community by Reflected DotCom (@reflected_dotcom_6456541f).</description>
    <link>https://dev.to/reflected_dotcom_6456541f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4284741%2F51a4759d-491e-40b2-b25d-1023628568b0.jpg</url>
      <title>DEV Community: Reflected DotCom</title>
      <link>https://dev.to/reflected_dotcom_6456541f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/reflected_dotcom_6456541f"/>
    <language>en</language>
    <item>
      <title>Why your CSS gradients go grey in the middle (and the one keyword that fixes it)</title>
      <dc:creator>Reflected DotCom</dc:creator>
      <pubDate>Sat, 05 Dec 2026 12:52:34 +0000</pubDate>
      <link>https://dev.to/reflected_dotcom_6456541f/why-your-css-gradients-go-grey-in-the-middle-and-the-one-keyword-that-fixes-it-2ko8</link>
      <guid>https://dev.to/reflected_dotcom_6456541f/why-your-css-gradients-go-grey-in-the-middle-and-the-one-keyword-that-fixes-it-2ko8</guid>
      <description>&lt;p&gt;Put this in a page and look at the middle of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.bar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#0000ff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#ffff00&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Blue on the left, yellow on the right, and right in the centre a flat, muddy grey. Nobody picked that grey. It is a side effect of how the browser blends the two colours.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the grey comes from
&lt;/h2&gt;

&lt;p&gt;By default, a gradient between two hex colours is blended in sRGB. The browser takes the red, green and blue channels and moves each one in a straight line.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;R&lt;/th&gt;
&lt;th&gt;G&lt;/th&gt;
&lt;th&gt;B&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Start &lt;code&gt;#0000ff&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;255&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Middle&lt;/td&gt;
&lt;td&gt;128&lt;/td&gt;
&lt;td&gt;128&lt;/td&gt;
&lt;td&gt;128&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;End &lt;code&gt;#ffff00&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;255&lt;/td&gt;
&lt;td&gt;255&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The halfway point is &lt;code&gt;#808080&lt;/code&gt;, a perfect neutral grey. Any two colours that sit opposite each other on the wheel do this: blue and yellow, red and cyan, purple and green. The channels cancel out on the way across.&lt;/p&gt;

&lt;p&gt;It is not a bug. sRGB was built to drive screens, not to describe how colours look to people, so a straight line through it is not a straight line for your eyes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: tell the browser which colour space to blend in
&lt;/h2&gt;

&lt;p&gt;CSS Color 4 lets you choose the interpolation space right inside the gradient:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.bar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;oklch&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#0000ff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#ffff00&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the whole change. In OKLCH every colour has a lightness (L), a chroma or "colourfulness" (C) and a hue angle (H). The browser now walks the hue around the wheel instead of cutting straight through the grey centre, and chroma stays up the whole way. Blue to yellow passes through teal and green, which is what most people expect a blue-to-yellow blend to look like.&lt;/p&gt;

&lt;p&gt;You can use the same syntax in &lt;code&gt;radial-gradient()&lt;/code&gt;, &lt;code&gt;conic-gradient()&lt;/code&gt; and &lt;code&gt;color-mix()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.badge&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;color-mix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#0000ff&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#ffff00&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  oklch or oklab?
&lt;/h2&gt;

&lt;p&gt;Both are perceptual spaces from the same family, and they behave differently in gradients.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;in oklab&lt;/code&gt;&lt;/strong&gt; blends in a straight line, like sRGB, but in a space that matches how we see lightness. Steps look evenly spaced, there are no dark bands, and nothing shifts hue. Between opposite colours it still gets less saturated in the middle, just far less grey than sRGB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;in oklch&lt;/code&gt;&lt;/strong&gt; keeps chroma and rotates the hue. Great for vivid, rainbow-like transitions. Between two very different hues it can pass through colours you did not ask for.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A rule of thumb that works for me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Two shades of the same colour, or a colour fading toward white or black: &lt;code&gt;in oklab&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Two different hues where you want it to stay bright: &lt;code&gt;in oklch&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Picking the direction around the wheel
&lt;/h2&gt;

&lt;p&gt;Hue is an angle, so there are always two ways to get from one hue to another. By default the browser takes the shorter one. You can change that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* the long way round: a full rainbow from red back to red-ish */&lt;/span&gt;
&lt;span class="nc"&gt;.rainbow&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;oklch&lt;/span&gt; &lt;span class="n"&gt;longer&lt;/span&gt; &lt;span class="n"&gt;hue&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;65&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;oklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;65&lt;/span&gt;&lt;span class="kt"&gt;%&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The options are &lt;code&gt;shorter hue&lt;/code&gt; (default), &lt;code&gt;longer hue&lt;/code&gt;, &lt;code&gt;increasing hue&lt;/code&gt; and &lt;code&gt;decreasing hue&lt;/code&gt;. &lt;code&gt;longer hue&lt;/code&gt; is a cheap way to get a full spectrum bar without listing seven stops.&lt;/p&gt;

&lt;h2&gt;
  
  
  Out-of-gamut colours
&lt;/h2&gt;

&lt;p&gt;OKLCH can describe colours that a normal sRGB screen cannot show. When a gradient in OKLCH passes through very high chroma, the browser maps those colours back into what the screen can display. In practice you will rarely notice. If you write your stops directly in &lt;code&gt;oklch()&lt;/code&gt;, keep chroma moderate (roughly 0.1 to 0.2 for most hues) and you stay safely inside sRGB on almost any screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fallback for older browsers
&lt;/h2&gt;

&lt;p&gt;Interpolation spaces in gradients are supported in current Chrome, Edge, Safari and Firefox. For older browsers, declare a plain gradient first. A browser that does not understand &lt;code&gt;in oklch&lt;/code&gt; will drop the second line and keep the first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.bar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#0000ff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#00a0a0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#ffff00&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;oklch&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#0000ff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;#ffff00&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The extra teal stop in the fallback stops the old gradient from going grey. It is not identical, but it is close enough for anyone on an old browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;If a gradient looks dull or grey in the middle, it is almost always sRGB blending.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;in oklch&lt;/code&gt; for vivid hue changes, &lt;code&gt;in oklab&lt;/code&gt; for smooth shades of one colour.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;longer hue&lt;/code&gt; when you actually want the long way round.&lt;/li&gt;
&lt;li&gt;Keep chroma moderate when you write &lt;code&gt;oklch()&lt;/code&gt; values by hand.&lt;/li&gt;
&lt;li&gt;Put an old-style gradient first as a fallback.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;I ran into this while building &lt;a href="https://shademix.com" rel="noopener noreferrer"&gt;Shademix&lt;/a&gt;, a free colour toolkit (eyedropper, RAL/NCS/Pantone-equivalent matching, OKLCH harmonies, WCAG contrast). If you want to play with OKLCH values and see the CSS for them, there is a &lt;a href="https://shademix.com/guides/oklch-cheatsheet.html" rel="noopener noreferrer"&gt;free OKLCH cheatsheet and converter&lt;/a&gt; on the site. No sign-up, nothing to install.&lt;/p&gt;

&lt;p&gt;What is the ugliest gradient you have shipped by accident? I am collecting them.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>design</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
