How to Add filter to the background image using CSS? Last Updated : 01 Oct, 2024 Comments Improve Suggest changes Like Article Like Report Adding filters to background images using CSS allows you to apply visual effects like blur, grayscale, brightness adjustment, and more without modifying the actual image file. CSS provides a set of filter functions that can be applied to elements with background images. This approach enhances design flexibility, enabling dynamic adjustments to background visuals to better match the website's aesthetic or enhance user experience.How to Apply CSS Filters to Background ImagesYou can apply filters to background images using the CSS filter property. The background image is set using the background-image property, and then filters are applied to modify the image's appearance.For example:filter: brightness(90%) reduces the brightness of the image, making it darker.filter: grayscale(70%) reduces color saturation, making the image less colorful. This is useful for improving text readability on top of the image.Common CSS Filter FunctionsHere are some commonly used CSS filter functions:blur(px): Applies a blur effect to the image.brightness(%): Adjusts the brightness. A value less than 100% darkens the image, while a value greater than 100% brightens it.grayscale(%): Converts the image to grayscale. A value of 100% makes the image fully grayscale.contrast(%): Adjusts the contrast. Values below 100% reduce contrast, and values above increase it.opacity(%): Adjusts the transparency of the image.sepia(%): Applies a sepia tone for a vintage effect.hue-rotate(deg): Rotates the image’s hue by a certain degree, changing its colors.Syntaxfilter: none | blur() | brightness() | contrast() | drop-shadow() | grayscale() | hue-rotate() | invert() | opacity() | saturate() | sepia() | url();Examples of Adding Filter in Background ImageHere are two examples of adding filters to the background image using CSS.Example 1: Applying a Filter to a Background ImageIn this example, we apply the brightness(90%) and grayscale(70%) filters to a background image. This makes the image slightly darker and reduces its colors, which can help improve readability for text placed on top. HTML <!DOCTYPE html> <html> <head> <style> body { background-image: url( "https://media.geeksforgeeks.org/wp-content/uploads/rk.png"); filter: brightness(90%); filter: grayscale(70%); text-align: center; } </style> </head> <body> <h2> GeeksForGeeks </h2> <h2> How to add a filter to a background image using CSS? </h2> </body> </html> Output:Example 2: Applying Multiple Filters to a Background ImageYou can also stack multiple filters on the same background image. In this example, we add both brightness and blur effects to the image: HTML <!DOCTYPE html> <html> <head> <style> .darkened-image { filter: brightness(50%); background-image: url( "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png"); height: 94px; width: 120px; } </style> </head> <body> <h1 style="color: green"> GeeksForGeeks </h1> <p> The image below is the normal image </p> <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png"> <p> The image below is the darkened image: </p> <div class="darkened-image"></div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Add filter to the background image using CSS? M manaschhabra2 Follow Improve Article Tags : Web Technologies HTML CSS CSS-Misc HTML-Misc HTML-Questions CSS-Questions +3 More Similar Reads How to Fit Background Image to Div using CSS? To fit a background image to a div using CSS, you can utilize the background-size property. Here are some approaches:1. Using background-size: cover;This method scales the background image to cover the entire div, maintaining the image's aspect ratio.HTML<html> <head> <style> .back 2 min read How to set a Responsive Full Background Image Using CSS ? The purpose of this article is to set a Responsive Full Background Image Using CSS.To set a Responsive Full Background Image using CSS we will use the CSS background-size property that has a value auto that tells the browsers to automatically scale the image's width and height based on the container 1 min read How to Add Image in Text Background using HTML and CSS ? In this article, we will use HTML and CSS to set the image in the text background. To set the image in the text background, some CSS property is used. To add an image in the text background using HTML and CSS, create a container element (e.g., a `<div>`), set its background to the desired imag 2 min read How to set multiple background images using CSS? The multiple background images for an element can be put in the HTML page using CSS. Use CSS background property to add multiple background images for an element in any pattern and use other CSS property to set the height and width of the images. The used background property are listed below: backgr 2 min read How to stretch and scale background image using CSS? The background-size property is used to stretch and scale the background image. This property set the size of the background image. Here we will see all possible examples of background-size and background-scale properties. Syntax: background-size: auto|length|cover|contain|initial|inherit;cover: Thi 2 min read How to give text or an image transparent background using CSS ? In this article, we will know to make the text or image a transparent background using the CSS & will see its implementation through the example. The opacity property is used to set image or text transparent using CSS. The opacity attribute is used to adjust the transparency of text or pictures. 2 min read How to Add a Background Image using Bootstrap 5 ? Bootstrap 5 is one of the alternatives for CSS styling of the elements. Rather than defining the separate properties for the elements, we can directly apply the Bootstrap 5 classes for more attractive styling of the elements. We can add a background image to the application in Bootstrap 5 using vari 2 min read How to transform background image using CSS3 ? In this article we will learn how to transform a background image using CSS3, The transform property in CSS is used to transform the background image. In Approach: The CSS transform property is used to apply the two-dimensional or three-dimensional transformation to an element. The transform propert 1 min read How to Add Background Image in CSS? The CSS background-image property is used to add an image as a background to an element.Syntaxbackground-image: url()1. Setting background Image of an ElementA background image is added to an h1 tag using the URL.HTML<h1 style="background-image: url( 'https://media.geeksforgeeks.org/wp-content/up 1 min read How to set background-image for the body element using CSS ? In this article, we set the image into the background using CSS property. The background-image property is used to set one or more background images to an element. By default, it places the image in the top left corner. To specify two or more images, separate the URLs with a comma. Syntax: backgroun 2 min read Like