How to create a gradient with 3 colors in CSS without color escalation

user8598044 picture user8598044 · Dec 1, 2017 · Viewed 21.5k times · Source

In this example I have a gradient of 2 colors, alignd to right.

Image

background: linear-gradient(to right, #c4d7e6 50%, #66a5ad 50%, #66a5ad 50%);

Is there any way I can have more than 2 colors? For example may I add red color on the right of the second one?

Answer

Joschi picture Joschi · Dec 1, 2017

Sure, just add color stops at every (100/numColors)%

div {
  background:linear-gradient(to right, #c4d7e6 0, #c4d7e6 33%, #66a5ad 33%, #66a5ad 66%, #ff0000 66%, #ff0000 100%);
  width: 100%;
  height:64px;
}
<div></div>