Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
How to Add Image in Text Background using HTML and CSS ?
Next article icon

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 Images

You 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 Functions

Here 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.

Syntax

filter: none | blur() | brightness() | contrast() | drop-shadow() | grayscale() | hue-rotate() | invert() | opacity() | saturate() | sepia() | url();

Examples of Adding Filter in Background Image

Here are two examples of adding filters to the background image using CSS.

Example 1: Applying a Filter to a Background Image

In 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 Image

You 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:



Next Article
How to Add Image in Text Background using HTML and CSS ?

M

manaschhabra2
Improve
Article Tags :
  • CSS
  • HTML
  • Web Technologies
  • CSS-Misc
  • CSS-Questions
  • HTML-Misc
  • HTML-Questions

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. [GFGTABS] HTML <html> <head> <st
    3 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 containe
    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. Syntax background-image: url()1. Setting background Image of an ElementA background image is added to an h1 tag using the URL. [GFGTABS] HTML <h1 style="background-image: url( 'https://media.geeksfor
    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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences