EN
CSS - filter style property only on background image
3 points
In this short article, we would like to show how to set filter style property only on background image using CSS.

In middle of 2024 year there is not available way to set filter style on background image so there is needed some trick. The most common way is to create a separated element inside a main element that has own background with set filter.
In this section we use a separated element inside to set background image with filter style. To make the separated element neutral we use position: absolute
with negative z-index
.
xxxxxxxxxx
1
<style>
2
3
div.element {
4
position: relative;
5
width: 225px;
6
height: 225px;
7
}
8
9
div.background {
10
position: absolute;
11
left: 0;
12
top: 0;
13
right: 0;
14
bottom: 0;
15
background: url('https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png') 0 0 / auto;
16
filter: blur(5px); /* <----- filter style property */
17
z-index: -1;
18
}
19
20
</style>
21
<div class="element">
22
<div class="background"></div>
23
Some content here ...
24
</div>
Warning: in some cases
z-index: -1
should be removed.