Palette maker

Rainbow Gradient: Colors, Backgrounds and CSS Codes

A rainbow gradient is a smooth blend through the spectrum, and the classic five-stop version uses red, yellow, green, blue and violet. In CSS that is linear-gradient(90deg, #FF0000, #FFFF00, #00FF00, #0000FF, #8B00FF).

Type
90°
 

More rainbow gradients to try

On this page
  1. Basics
  2. Color codes
  3. CSS
  4. Fix muddy
  5. Palettes
  6. Contrast
  7. Web and UI
  8. Print and more
  9. History
  10. Animation
  11. FAQ

In twelve years of building color systems, the rainbow is the gradient I see misused most, usually because of one muddy stretch or unreadable text. Use the gradient studio above to move stops, change the angle and switch type, then copy the CSS. The sections below cover exact codes, the traps and where a rainbow works.

What makes a rainbow gradient different from a color wheel

A rainbow gradient walks through hues in spectral order with every stop at full saturation. Red, yellow, green, blue and violet are the anchors, and the browser invents everything between them. The midpoint of red and yellow, for example, lands on , a clean orange, so you get orange without placing a stop for it. The orange gradient page shows how that family behaves when you want to control it.

It helps to know what a rainbow gradient is not. An ombre stays inside one hue, a sunset gradient stays in the warm end with softened pinks and golds, and a holographic gradient shifts between pastel pinks and blues. The rainbow is the loud one: pure hues, fixed order, no neutral to rest on. That suits playful, inclusive or energetic work, and it needs a plan before it goes near text.

Rainbow gradient hex, RGB, HSL and CMYK codes

These five values are converted straight from the hex codes. HSL shows the logic: the hues sit at 0, 60, 120, 240 and about 273 degrees, and all five share 100% saturation and 50% lightness. CMYK figures are simple mathematical conversions, so treat them as a starting point for print.

Color HEX RGB HSL CMYK
Red 255, 0, 0 0, 100%, 50% 0, 100, 100, 0
Yellow 255, 255, 0 60, 100%, 50% 0, 0, 100, 0
Green 0, 255, 0 120, 100%, 50% 100, 0, 100, 0
Blue 0, 0, 255 240, 100%, 50% 100, 100, 0, 0
Violet 139, 0, 255 273, 100%, 50% 45, 100, 0, 0

Watch the CSS keywords. The word green gives , a much darker color than the spectral green here, which is lime (). The keyword violet gives , a pale pink-purple, and indigo gives . If you paste a keyword rainbow and wonder why it looks washed out, that is usually the reason, so use hex codes for a predictable result.

Copy-ready CSS for linear, radial and conic rainbows

The standard left-to-right version is one line. Add a solid fallback color first so older or restricted contexts still show something sensible.

.rainbow {
  background-color: ;
  background: linear-gradient(90deg, , , , , );
}

Angles work like a compass: 90deg runs left to right, 180deg runs top to bottom and 135deg gives a diagonal that suits cards and hero sections. A radial version radiates from the center, and a conic version sweeps around a point, which is how you build a color wheel. Repeat the first color at the end of a conic gradient so the seam disappears.

.glow  { background: radial-gradient(circle, , , , , ); }
.wheel { background: conic-gradient(, , , , , ); }
.stripes { background: linear-gradient(90deg,  0 20%,  20% 40%,  40% 60%,  60% 80%,  80% 100%); }

The third rule shows hard stripes: giving each color a start and end position removes the blend completely. It is the quickest way to draw a flag-style band.

Try this: In the studio above, switch to conic, then drag the violet stop to 90%. Notice how the seam back to red gets a tighter, more dramatic transition.

Why the green to blue stretch goes muddy, and the fix

Blend and in plain sRGB and the midpoint is roughly , a dark teal. Green is bright (relative luminance about 0.72) and blue is dark (about 0.07), and the average of the channels looks dimmer than either neighbor. That dark band is what people call the muddy middle, and it is easy to spot on any five-stop rainbow. The teal gradient page covers that color in its own right, but here it is a side effect you usually want to remove.

Which change most reliably brightens the middle of a rainbow gradient?

Interpolating in oklch keeps lightness steadier, so the green to blue midpoint does not dip into a dark teal.

There are three dependable fixes:

  1. Add a cyan stop halfway between green and blue, at 62% on a five-stop run. This is what a real spectrum does.
  2. Interpolate in a perceptual space: linear-gradient(in oklch 90deg, #FF0000, #FFFF00, #00FF00, #0000FF, #8B00FF). Current major browsers support it, and older ones ignore the in oklch and fall back to a normal blend.
  3. Use fewer, closer hues. A two-stop red to blue gradient avoids the problem entirely, because it never has to cross the green zone.

The blue to violet end has a smaller version of the issue, because to passes through a deep, saturated indigo near . That one usually looks fine, and it is the reason most rainbows do not need a separate indigo stop.

Rainbow palettes to copy: bright, pastel and deep

Pure rainbow colors are rarely the best choice for a finished layout. The four sets below keep the hue order but change saturation and lightness for different jobs. Full Spectrum is the one the studio starts with, and the others are the versions I reach for in client work.

Full Spectrum

Hero strips, kids' apps and loud accent bars on white or black.

Pastel Candy

Soft backgrounds, stationery and baby brands where dark text must stay readable.

Deep Prism

Dark-mode interfaces and posters that carry white text across every stop.

Neon Arc

Event graphics, music covers and gaming banners on near-black backgrounds.

Pastel Candy suits backgrounds where dark text must stay readable, and it pairs naturally with a pink to purple gradient when you want to warm the violet end. Deep Prism darkens every stop for white text, and Neon Arc leans on a hot pink start and a cyan-mint middle for dark backgrounds.

Text on a rainbow: contrast and accessibility

No single text color works across a pure rainbow. These ratios are computed from the WCAG relative luminance formula, where 4.5:1 is the AA minimum for normal text and 3:1 for large text:

  • Red : 4.00:1 with white, 5.25:1 with black
  • Yellow : 1.07:1 with white, 19.56:1 with black
  • Green : 1.37:1 with white, 15.30:1 with black
  • Blue : 8.59:1 with white, 2.44:1 with black
  • Violet : 5.93:1 with white, 3.54:1 with black

Black fails on blue and white fails on yellow and green, so text laid straight across the gradient will always lose somewhere. On a kids’ learning app I once replaced white labels sitting on a rainbow bar with labels on small solid dark chips, and every label became readable at any position. The practical rule: keep the rainbow decorative, and put copy on a solid panel in black or a deep neutral.

Which text color is readable across a whole pure rainbow gradient?

Black fails on blue and white fails on yellow and green, so text needs its own solid background.

Rainbow gradients in web and app design

Thin is the safe way to use a rainbow in an interface. A 4px strip above a header, a progress bar, a focus ring or a button underline carries the energy without fighting the content. Full-bleed rainbow hero sections need a calmer treatment: lower the opacity to around 15 to 25 percent over white, or fade the gradient out toward a white gradient so the lower half of the screen stays clean.

Four Aa text tiles on yellow and blue backgrounds with WCAG contrast ratios marked AA pass or AA fail
White fails on yellow and black fails on blue, so rainbow text needs a solid panel.

Dark backgrounds are kinder to saturated colors. Pure hues glow against near-black, which is why Neon Arc looks better on dark than on white. For soft, blurred “aurora” backgrounds, place a large radial rainbow behind a layer with backdrop-filter: blur(40px) and keep the text in the foreground on a solid or semi-solid surface.

Branding, print, interiors and fashion

Rainbow marks work for brands built on variety, community or play, such as education, kids’ products, creative tools and festivals. They cope badly with small sizes, because a five-hue gradient turns into noise at 16 pixels. Provide a one-color version of any rainbow logo before you sign it off.

Two panels compare green and blue on screen with HEX and RGB codes against their duller CMYK print versions
Pure green #00FF00 and blue #0000FF look duller in print, because CMYK inks cannot reproduce them.

Print is where I got surprised. On a festival poster proof, the green and blue stops came out visibly duller than the screen design, because and sit outside what CMYK inks can reproduce. We fixed it by choosing the nearest printable greens and blues on the proof and, for the one run that mattered, adding a spot ink. Always request a proof before a rainbow goes to press.

In interiors, a full-strength rainbow wall is rare, and designers lean toward soft tints: a painted ombre in pastel stripes or a single band of color on a nursery wall. Fashion uses the same logic with tie-dye, ombre knits and printed silk, where hues blend on fabric rather than on a screen. In art, wet-on-wet watercolor gives the most natural rainbow blend, because pigments mix on the paper.

Newton, Pride and the seven-color question

A real rainbow is continuous, and the number of colors we name is a convention. Isaac Newton’s published spectrum counted seven: red, orange, yellow, green, blue, indigo and violet. On a screen, indigo () is hard to tell apart from blue and violet, which is why five stops are usually enough.

Stripes versus blend

The Pride flag is a set of hard bands, not a gradient. Gilbert Baker's 1978 original had eight stripes, and the common modern version has six. Use the hard-stripe CSS above, not a smooth blend.

If you need ROYGBIV, add orange between red and yellow and indigo before violet. Spread the seven stops evenly at about 17% intervals and check the green to blue stretch again, since adding stops does not remove the dark teal on its own.

Animated rainbow text and backgrounds

Making the gradient wider than its box and sliding it creates a shimmer. Set background-size: 300% 100%, animate background-position and clip it to text with background-clip: text if you want a rainbow headline.

.shimmer {
  background: linear-gradient(90deg, , , , , , );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: slide 6s linear infinite;
}
@keyframes slide { to { background-position: 300% 0; } }
@media (prefers-reduced-motion: reduce) { .shimmer { animation: none; } }

Repeating the first color at the end makes the loop seamless. The reduced-motion rule matters, because constant color movement can bother some users. Rainbow text is also a contrast risk, since each letter changes color against its background, so reserve it for a single large headline.

The colors behind these gradients

Rainbow Gradient: questions people ask

What is the hex code for a rainbow gradient?

A gradient is made of several colors, so there is no single code. The five-stop version on this page uses #FF0000, #FFFF00, #00FF00, #0000FF and #8B00FF. Add #FF8000 or #00FFFF between stops if you want a fuller spectrum.

How do I make a rainbow gradient in CSS?

Use background: linear-gradient(90deg, #FF0000, #FFFF00, #00FF00, #0000FF, #8B00FF). Change 90deg to alter the direction, or swap in radial-gradient or conic-gradient for a circular look.

How many colors should a rainbow gradient have?

Five stops are enough, because the browser blends orange and cyan on its own. Use six or seven only when you need to control the exact orange, cyan or indigo.

Why does my rainbow gradient look brown or dull in the middle?

Blending in plain sRGB drops brightness between green and blue, which gives a dark teal. Add a #00FFFF stop or interpolate in oklch to keep the middle bright.

Can I print a rainbow gradient in CMYK?

Yes, but pure green, blue and violet sit outside the CMYK range, so they print duller than on screen. Ask for a proof and expect softer greens and blues.

Keep exploring