-1

I have set the background colour to a linear gradient and I want the background colour to be a blur. I have tried a few codes but couldn't make it work. Here is my code:

body{
    background: linear-gradient(100deg, #3B53D6,#4AFAFA);
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    height: 200px; /* Make sure the body is visible */
    width: 200px;
}
<body>
</body>

I am learning CSS, please help me! Thank you in advance!

noobaka
  • 37
  • 7

3 Answers3

2

Just try adding filter: blur(8px);, -webkit-filter: blur(8px);.

Code:

body {
    background: linear-gradient(100deg, #3B53D6,#4AFAFA);
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    /* Add the blur effect */
    filter: blur(8px);
    -webkit-filter: blur(8px);
}

You may increase the blur by changing 8px into any number you want.

For example, 10px:

filter: blur(10px);, -webkit-filter: blur(10px);.

Learn more in MDN.

Kevin M. Mansour
  • 2,915
  • 6
  • 18
  • 35
1

Just set the background separately from the body, i.e. you can use a pseudo element and filter just this pseudo.

html {
    width: 100%;
    height: 100%;
}

body {
    width: 100%;
    height: 100%;
    position: relative;
    box-sizing: border-box;
    margin: 0;
    padding: 0;    
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: linear-gradient(100deg, #3B53D6,#4AFAFA);
    filter: blur(10px);
}
Kevin M. Mansour
  • 2,915
  • 6
  • 18
  • 35
0

You can make the gradient a pseudo element on the body and blur that:

body {
  padding: 0;
  margin: 0;
  position: relative;
  box-sizing: border-box;
  min-height: 100vh;
}

body::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(100deg, #3B53D6, #4AFAFA);
  filter: blur(5px);
  z-index: -1;
}
<body>
  <div>
    content content content
  </div>
</body>

If you add filter: blur() to the body, that will blur all of the children as well.

disinfor
  • 10,865
  • 2
  • 33
  • 44