W3docs

How to Add a Blur Filter to the Background Image

Learn How to Apply a Blur Filter to a Background Image with W3docs tutorial. Follow up the steps and create a blurred background image for your website.

In this snippet, you can find out how to apply a blur filter to the background image. It is very simple and fast!

Follow up the steps and create a blurred background image for your website.

Create HTML

  • Begin by creating a <div> element with a class of "image".
  • Create another <div> element with a class name "text". Here, also add <h1>, <h2>, and <p> elements.

How to create an HTML <div> element?

<div class="image"></div>
<div class="text">
  <h1>W3DOCS</h1>
  <h2>Blurred Background Image</h2>
  <p>Snippet</p>
</div>

Add CSS

  • Add the link of the image with the background-image property.
  • Set the height of the image with the height property, then specify the position of the image with the background-position property. Here, we set the "center" value.
  • After applying the <span class="property">background-position</span>, make the image not repeated by setting the background-repeat property to "no-repeat".
  • Specify the background-size into "cover", which scales background image as large as possible to cover all the background area.
  • Use the filter property to make our image blur. The <span class="property">filter</span> property has the "blur" value, which applies blur on an image. It is specified in pixels. The larger the value, the more blur will be applied. We set it to "5px".
Tip

Note: Vendor prefixes for the filter property are largely obsolete in modern browsers. The standard filter property is sufficient for current versions of all major browsers.

Here is what we have. We’re going close to the end!

How to style an HTML tag, using the background-image, height, background-position, background-repeat, background-size and filter properties?

.image {
  position: relative;
  background-image: url("/uploads/media/default/0001/05/15552fb22caf79be6cc2c60b9a1afe9016889422.jpeg");
  height: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  filter: blur(5px);
}

So, half of the work is done. Now, style the text by using the color, font-weight, border and other properties.

How to style an HTML tag, using the color, font-weight, border, position, top, left, transform, z-index, width, padding and text-align properties?

.text {
  color: #eeeeee;
  font-weight: bold;
  border: 3px solid #cccccc;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 80%;
  padding: 20px;
  text-align: center;
}

Now let’s see the result.

Example of adding a blurred background image:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body,
      html {
        height: 100%;
        margin: 0;
        font-family: Arial, Helvetica, sans-serif;
      }
      h2 {
        font-size: 30px;
      }
      .image {
        position: relative;
        background-image: url("/uploads/media/default/0001/05/15552fb22caf79be6cc2c60b9a1afe9016889422.jpeg");
        height: 100%;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
        filter: blur(5px);
      }
      .text {
        color: #eeeeee;
        font-weight: bold;
        border: 3px solid #cccccc;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 80%;
        padding: 20px;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="image"></div>
    <div class="text">
      <h1>W3DOCS</h1>
      <h2>Blurred Background Image</h2>
      <p>Snippet</p>
    </div>
  </body>
</html>

Result

<div class="demo my-20"> XFI5 </div> XFI6 <h1> W3DOCS </h1> <h2> Blurred Background Image </h2> <p> Snippet </p> XFI7 </div> Let’s see another example with the blurred background image.

Example of adding a blurred background image with fixed positioning:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .background-image {
        position: fixed;
        left: 0;
        right: 0;
        z-index: 1;
        display: block;
        background-image: url("/uploads/media/default/0001/01/4982c4f43023330a662b9baed5a407e391ae6161.jpeg");
        width: 1200px;
        height: 800px;
        filter: blur(5px);
      }
      .content {
        position: fixed;
        left: 0;
        right: 0;
        z-index: 9999;
        margin-left: 20px;
        margin-right: 20px;
        color: #fff;
      }
    </style>
  </head>
  <body>
    <h2>:checked selector example</h2>
    <div class="background-image"></div>
    <div class="content">
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis aliquam erat in ante malesuada, facilisis semper nulla semper. Phasellus sapien neque, faucibus in malesuada quis, lacinia et libero. Sed sed turpis tellus. Etiam ac aliquam tortor, eleifend rhoncus metus. Ut turpis massa, sollicitudin sit amet molestie a, posuere sit amet nisl. Mauris tincidunt cursus posuere. Nam commodo libero quis lacus sodales, nec feugiat ante posuere. Donec pulvinar auctor commodo. Donec egestas diam ut mi adipiscing, quis lacinia mauris condimentum. Quisque quis odio venenatis, venenatis nisi a, vehicula ipsum. Etiam at nisl eu felis vulputate porta.
      </p>
      <p>
        Fusce ut placerat eros. Aliquam consequat in augue sed convallis. Donec orci urna, tincidunt vel dui at, elementum semper dolor. Donec tincidunt risus sed magna dictum, quis luctus metus volutpat. Donec accumsan et nunc vulputate accumsan. Vestibulum tempor, erat in mattis fringilla, elit urna ornare nunc, vel pretium elit sem quis orci. Vivamus condimentum dictum tempor. Nam at est ante. Sed lobortis et lorem in sagittis. In suscipit in est et vehicula.
      </p>
    </div>
  </body>
</html>