The word “gradient” implies a transition from one color to another color. That’s super useful in web design and can create lovely effects. We’re going to skip that whole “transition” part though and see what kind of CSS trickery that unlocks.
Here’s an example of “traditional” gradients where colors slowly fade from one to another.
![](https://i2.wp.com/css-tricks.com/wp-content/uploads/2020/04/gradient-sunset.png?fit=1024%2C678&ssl=1)
There is a concept called color-stops with gradients that allow you to control the position of where colors start transitioning from one to the next. Here’s an example where the first color hangs on for most of the way:
.stripe {
height: 100px;
background: linear-gradient(to right, red 85%, blue);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-1.png?resize=1024%2C136&ssl=1)
Here’s the trick: the color stops can get closer and closer to each other, and actually be at the same point. Meaning that instead of the color transitioning at all, one color stops and the other color can start at an exact point. Here’s a visual explanation of converging color stops:
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-2.png?resize=1024%2C442&ssl=1)
The bottom example there almost looks like it’s two separate elements with two separate backgrounds, but nope, it’s a single element with hard-stop gradients splitting the space visually. If you needed to make vertical columns and handle their backgrounds all on one parent element, this is a possibility! In fact, because the background will cover the whole area, you don’t have to worry about the elements “stretching” the full height, which made this a great trick when we needed to make columns based on floats or inline-block elements.
Extending the concept of hard stops, we can make a color-striped bar. Here are variations of it made by moving the background-position
.
.stripe {
height: 15px;
background: linear-gradient(
to right,
red,
red 20%,
orange 20%,
orange 40%,
yellowgreen 40%,
yellowgreen 60%,
lightblue 60%,
lightblue 80%,
purple 80%,
purple
);
margin: 0 0 20px 0;
}
.stripe:nth-child(2) {
background-position-x: -10vw;
}
.stripe:nth-child(3) {
background-position-x: -20vw;
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-3.png?resize=1024%2C117&ssl=1)
Speaking of stripes, these hard-stop gradients are great for striped backgrounds of any kind. It gets a little easier with repeating gradients (e.g. repeating-linear-gradient()
) as you don’t have to fill 100% of the space, you can use pixels and stop where you need to.
.stripes {
background-color: #ffd600;
background-image: repeating-linear-gradient(
45deg,
transparent,
transparent 9px,
#f4ff81 9px,
#f4ff81 10px
);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-4.png?resize=658%2C398&ssl=1)
.stripes {
background-color: #cfd8dc;
background-image: repeating-linear-gradient(
45deg,
transparent,
transparent 1px,
#90a4ae 1px,
#90a4ae 2px
);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-5.png?resize=656%2C398&ssl=1)
.stripes {
background-color: #e53935;
background-image: repeating-linear-gradient(
10deg,
transparent,
transparent 20px,
#c62828 20px,
#c62828 23px
);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/gradd-6.png?resize=734%2C394&ssl=1)
.stripes {
background-color: #689f38;
background-image: repeating-linear-gradient(
-25deg,
transparent,
transparent 40px,
#aed581 40px,
#aed581 50px
);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-7.png?resize=728%2C396&ssl=1)
.stripes {
background-image: repeating-linear-gradient(
90deg,
rgba(224, 82, 67, 0.5) 0px,
rgba(224, 82, 67, 0.5) 40px,
transparent 40px,
transparent 80px
),
repeating-linear-gradient(
0deg,
rgba(224, 82, 67, 0.5) 0px,
rgba(224, 82, 67, 0.5) 40px,
transparent 40px,
transparent 80px
),
linear-gradient(90deg, hsl(250, 82%, 1%), hsl(250, 82%, 1%));
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-8.png?resize=656%2C396&ssl=1)
.stripes {
background-image: repeating-linear-gradient(
45deg,
hsla(312, 0%, 63%, 0.05) 0px,
hsla(312, 0%, 63%, 0.05) 10px,
transparent 10px,
transparent 100px
),
repeating-linear-gradient(
90deg,
hsla(312, 0%, 63%, 0.05) 0px,
hsla(312, 0%, 63%, 0.05) 50px,
transparent 50px,
transparent 100px
),
linear-gradient(90deg, hsl(80, 0%, 20%), hsl(80, 0%, 20%));
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/grad-9.png?resize=650%2C388&ssl=1)
There are other types of gradients as well! We can use hard-stops with radial-gradient
and repeating-linear-gradient
as well!
.stripes {
background: repeating-radial-gradient(
circle at 100%,
#333,
#333 10px,
#999 10px,
#999 20px
);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/radgrad-1.png?resize=656%2C394&ssl=1)
.stripes {
background-image: radial-gradient(#90caf9 20%, transparent 20%),
radial-gradient(#1e88e5 20%, transparent 20%);
background-color: #64b5f6;
background-position: top left, 50px 50px;
background-size: 100px 100px;
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/radgrad-2.png?resize=656%2C396&ssl=1)
.stripes {
background-image: radial-gradient(
circle at top left,
#ec407a,
#ec407a 20%,
#7e57c2 20%,
#7e57c2 40%,
#42a5f5 40%,
#42a5f5 60%,
#26a69a 60%,
#26a69a 80%,
#9ccc65 80%
);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/radgrad-3.png?resize=656%2C398&ssl=1)
.stripes {
background: repeating-radial-gradient(
circle at bottom right,
#eee,
#ccc 50px
);
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/radgrad-4.png?resize=650%2C396&ssl=1)
Notice in that last example, you still see some color fading stuff going on. A hard-stop gradient doesn’t have to be used exclusively. That one has just one hard stop that repeats.
Conical gradients are another prime canidate for hard stop gradients, as when applied into a circle (e.g. border-radius: 50%
) they become instant pie charts!
.chart {
background: conic-gradient(
#f15854 4%,
#4d4d4d 0 8%,
#5da5da 0 17%,
#decf3f 0 48%,
#b276b2 0 54%,
#faa43a 0
);
border-radius: 50%;
height: 0;
padding-top: 100%;
}
![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/09/pie-chart.png?resize=612%2C542&ssl=1)