Red to blue gradient
A smooth red to blue gradient in CSS, blended in OKLab so the middle stays clean. Change the angle, add colors and copy the code.
Colors
OKLab keeps the middle bright. sRGB is how old browsers blend and often turns gray in the middle.
CSS
background: linear-gradient(90deg, #ff0000, #e2384b, #c6496d, #a95189, #8c53a2, #6f50ba, #5147d2, #3036e8, #0000ff);
background: linear-gradient(90deg in oklab, #ff0000, #0000ff);Tailwind CSS v4
bg-linear-90/oklab from-[#ff0000] to-[#0000ff]Colors along the gradient
How red and blue blend in each color space
The same two colors give a different middle depending on the space the browser blends in. These are the exact colors at 50%. These two colors blend almost the same way in every space: the middle is #8c53a2 in OKLab and #800080 in sRGB, so any of them works.
| Blend in | Gradient preview | Middle color | Lightness | Chroma |
|---|---|---|---|---|
| OKLab | #8c53a2 | 54% | 0.134 | |
| OKLCH | #b700be | 54% | 0.285 | |
| sRGB | #800080 | 42% | 0.193 | |
| LCH | #cd007e | 54.4% | 0.384 | |
| HSL | #ff00ff | 70.2% | 0.322 |
Questions about this gradient
How do I make a red to blue gradient in CSS?
Use background: linear-gradient(90deg in oklab, #ff0000, #0000ff). Add a line before it with the sRGB version for very old browsers. Interpolation in OKLab works in all current browsers.
What color is halfway between red and blue?
Blended in OKLab, the color halfway between red and blue is #8c53a2. A plain sRGB blend gives #800080.
How do I make a red to blue gradient in Tailwind CSS?
In Tailwind CSS v4 use the classes bg-linear-90/oklab from-[#ff0000] to-[#0000ff].