csslinear-gradientsnoise

How can we add noise to linear-gradient background?


How can we add noise to linear-gradient background?

body{
height: 100vh;
background:
linear-gradient(red, transparent ),
linear-gradient(to top left, blue, transparent),
linear-gradient(to top right, rgb(124, 211, 134), transparent );
background-blend-mode: screen;
}

Solution

  • It is possible with more than 2 colors using ::pseudo element.

    @import "https://cdn.jsdelivr.net/gh/KunalTanwar/normalize/css/normalize.inter.min.css";
    
    body {
      height: 100%;
      display: grid;
      place-items: center;
    }
    
    .container {
      width: 150px;
      aspect-ratio: 1/1;
      background-image: linear-gradient(to right, #833ab4, #fd1d1d, #fcb045);
    }
    .container::after {
      content: "";
      position: absolute;
      inset: 0 0 0 0;
      width: 100%;
      height: 100%;
      mix-blend-mode: multiply;
      background-repeat: no-repeat;
      background-position: center center;
      background-image: url(https://grainy-gradients.vercel.app/noise.svg);
    }
    <div class="container"></div>