Home / Learn / How to make an animated gradient background

How to make an animated gradient background

A background whose colors drift slowly, adding life to a page without video or heavy images.

Steps

  1. Make an oversized gradient with background-size 300%.
  2. Animate background-position with keyframes.
  3. Use 6 seconds or more so it stays calm.

The code

.bg{background:linear-gradient(120deg,#ff5e1a,#7c3aed,#06b6d4,#ff5e1a);background-size:300% 300%;animation:move 6s ease infinite}
@keyframes move{0%{background-position:0 50%}50%{background-position:100% 50%}100%{background-position:0 50%}}

Want ready-made variations? The library has hundreds, each with standalone code.