Looped color animation
CSS
.rainbow {
animation: rainbow 2s alternate infinite;
}
@keyframes rainbow {
0% { background: #ff004d; }
20% { background: #ff77ab; }
50% { background: #00e756; }
80% { background: #29adff; }
100% { background: #ff77ab;}
}
Web Animations API
let el = document.querySelector('.rainbow');
el.animate([
{ background: '#ff004d', offset: 0 },
{ background: '#ff77ab', offset: 0.20 },
{ background: '#00e756', offset: 0.5 },
{ background: '#29adff', offset: 0.80 },
{ background: '#ff77ab', offset: 1 }
], {
duration: 2000,
direction: 'alternate',
iterations: Infinity
});