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 Change the Checked Mark Color of a Checkbox using CSS?
Next article icon

How to change the color of an image to black and white using CSS ?

Last Updated : 10 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

To change an image’s color to black and white using CSS. This can be achieved by applying the filter property, which allows you to manipulate the visual effects of an image. We’ll explore two different methods for converting an image to grayscale (black and white).

Methods to Convert an Image to Black and White Using CSS

There are two common ways to make an image appear in black and white using CSS:

  1. Using the grayscale() Method
  2. Using the brightness() and saturate() Methods

1. Using the grayscale() Method

The grayscale() Method converts the colors of an element to black and white. The level of grayscale is determined by the percentage specified:

  • 0% means the original colors of the image.
  • 100% means the image is completely grayscale (black and white).

Syntax:  

filter: grayscale(100%)

Example:  We will apply the grayscale() filter to an image to convert it to black and white.

HTML
<!DOCTYPE html> <html> <head>     <title>         How to change the color of an images         to black and white using CSS?     </title>     <style>         .gfg {             -webkit-filter: grayscale(100%);             filter: grayscale(100%);         }     </style> </head> <body>     <h2>GeeksForGeeks</h2>     <h2>         How to change the color of an images         to black and white using CSS?     </h2>     <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png">     <br>     <b>After Convert to Black and White</b> <br>     <img class="gfg"           src=  "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png"> </body> </html> 

Output:

2. Using brightness() and saturate() Methods

This method provides another way to achieve a black-and-white effect by adjusting the brightness and saturation of the image:

  • brightness() controls the brightness level of the image.
  • saturate() controls the saturation level (color intensity) of the image.

Setting the saturation to 0% effectively removes all colors, while adjusting brightness can fine-tune the intensity of black and white.

Syntax:

filter: brightness(0.5) saturate(0%);

Example: We will use both brightness() and saturate() to convert the image to black and white.

HTML
<!DOCTYPE html> <html> <head>     <title>         How to change the color of an images         to black and white using CSS?     </title>     <style>         .gfg {             filter: brightness(0.5) saturate(0%);         }     </style> </head> <body>     <h2>GeeksForGeeks</h2>     <h2>         How to change the color of an images         to black and white using CSS?     </h2>     <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png">     <br>     <b>After Convert to Black and White</b> <br>     <img class="gfg"           src=  "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20191121162913/s11.png"> </body> </html> 

Output:



Next Article
How to Change the Checked Mark Color of a Checkbox using CSS?

M

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

Similar Reads

  • How to change color of PNG image using CSS?
    Given an image and the task is to change the image color using CSS. Use filter function to change the png image color. Filter property is mainly used to set the visual effect to the image. There are many property value exist to the filter function. filter: none|blur()|brightness()|contrast()|drop-sh
    1 min read
  • How to Change the Background Color of Table using CSS?
    Changing the background color of a table using CSS can help improve the visual appearance of a website or web application. we will learn how to change the background color of the table using CSS with different approaches. These are the following approaches: Table of Content Using Inline CSSUsing Int
    2 min read
  • How to Change the Color of Bullets using CSS?
    Changing the color of bullets using CSS means styling the bullet points in a list (<ul> or <ol>) to have a different color than the text. This can be done using pseudo-elements or setting the color property on the list item, enhancing design consistency. 1. Adding An Extra MarkupBy addin
    2 min read
  • How to Change the Checked Mark Color of a Checkbox using CSS?
    Checkboxes are commonly used on websites to enable users to make selections, such as agreeing to terms and conditions or choosing preferences. A checkbox is a small square box in forms that users can click to select or deselect an option. By default, the checkmark inside the checkbox has a basic sty
    5 min read
  • How to Drop fill color to change the image color using HTML and CSS ?
    In this article, we are going to create a Drop-fill color effect using HTML & CSS in which the image gets colored when we hover over it. It appears when you hover over the image a drop of color falls over the image which changes the color of the image from gray to colored. Approach: The followin
    4 min read
  • How to change the color of any div that is animated using jQuery ?
    In this article, we will learn to change the color of any HTML div that is animated using jQuery.We will be using the jQuery .animate() method to change the background colors of any element. The jQuery .animate() method is used to create smooth animations by changing the CSS properties of elements o
    2 min read
  • How to Add filter to the background image using CSS?
    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
    3 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 change the color of an icon using jQuery ?
    In this article, we will see how to change the color of the icon using jQuery. To change the color of the icon, we will use a jquery method. jQuery css() method this method is used to change the styling of a particular selector. This method is also can be used for changing the color of the icon. Fir
    2 min read
  • How to randomly change image color using HTML CSS and JavaScript ?
    In this article, we will create a webpage where we can change image color randomly by clicking on the image using HTML, CSS, and JavaScript. The image color will change randomly using the JavaScript Math random() function. Approach: First of all select your image using HTML <img> tag.In JavaSc
    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