How to create a gradient background color on scroll with CSS?

CSSWeb DevelopmentFront End Technology

To create a gradient background color on scroll, the code is as follows −


 Live Demo

<!DOCTYPE html>
   body {
      height: 250vh;
      color: white;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      background: linear-gradient(
         #a47dff 0%,
         #4e28a7 40%,
         #22053d 65%,
         #72a4ff 75%
<h1>Change Background Gradient on Scroll Example</h1>
<p style="font-size: 30px;">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus, laborum minus? Vero accusantium laborum quas cum, sed obcaecati quibusdam dignissimos.
<h2 style="position:fixed;">Scroll to see the effect.</h2>


The above code will produce the following output −

While scrolling the gradient will shift from dark blue to light blue −

Published on 08-May-2020 16:23:12