As far as I know there's no way to directly apply the backdrop-filter:blur to a text element.
Create a containerApply a background to it (or to its ::before pseudo-element)Use the filter:blur so that the container's background is blurredApply a svg mask onto the svg element and then apply the same background to the container (or to its ::before pseudo-element)
This way we have the blurried background on top that gets masked and the non-blurry version under it.
NOTE: applying the background to the container's ::before pseudo element will allow you to modify the background without touching the svg mask (usefull if you need to flip the background to create more contrast but you can't modify the original image).
- Create a container
- Apply a background to it
- Create a svg element which will represent our "text"
- Apply the backdrop-filter:blur to the svg element
- Apply the svg-mask to the svg element
This way we have the effect we would have if the backdrop-filter: blur could be applied to text.
This one is the one which performs the best because it's the only method that doesn't require the svg element to duplicate the background (which would have to be repainted at every frame because of the background-attachment:fixed attribute).
You can test the performances by using the testSmoothness()
method in the browser console in combination with the browser profiler.
Create a containerApply a background to itCreate a svg element which will represent out "text"Apply the blurry version of the background to the svg elementApply the svg-mask to the svg element
Applying the blur effect alone will give us a low contrast-ratio (hard to read text).
To counter this I applied a shadow to the svg:
- Create a svg element in the document
- Inside the
<defs>
tag create a filter with the<filter>
tag and give it a unique id - Inside the
<filter>
tag create a<feGaussianBlur>
with astdDeviation
of your choice (4 and 5 are good initial numbers) - Still inside the
<filter>
tag, create a<feComposite>
with theout
operator andin2
set toSourceGraphics
- To shape our shadow we'll use an
<image>
outside of the<defs>
tag - Set the
url
of the<image>
'sfilter
attribute to the same id you gave to the<filter>
tag (see point 2 above) - Set the
xlink:href
attribute's value to the same one of your svg's path
This is the reference code:
<svg>
<defs>
<filter id = "trans-shadow">
<feGaussianBlur stdDeviation = "5"/>
<feComposite operator = "out" in2 = "SourceGraphic"/>
</filter>
</defs>
<image filter = "url(#trans-shadow)" x = "0" y = "0" width = "100%" height = "100%" xlink:href = "./SVG.svg" />
</svg>
If the text still isn't easy to read remember that with the Method 2 you can still set an rgba(255,255,255,0.xyz) background-color and that with the all the 3 methods you can add a saturation to the filter/backdrop-filter!