The Wayback Machine - https://web.archive.org/web/20250115224726/https://www.geeksforgeeks.org/css-grayscale-function/
Open In App

CSS grayscale() Function

Last Updated : 30 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The grayscale() function in CSS is an inbuilt function that is used to apply a filter to the image to set the grayscale of the image.

Syntax:

grayscale( amount )

Parameters: This function accepts a single parameter amount that holds the value of grayscale. The value of grayscale is set in terms of number and percentage. The value 0% represents the original image while the value between 0% to 100% represents the linear multipliers on the effect.


Example: The below example illustrates the grayscale() function in CSS.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>CSS grayscale() Function</title>
    <style>
    h1 {
        color: green;
    }
    
    body {
        text-align: center;
    }
    
    .grayscale_effect {
        filter: grayscale(100%);
    }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h2>CSS grayscale() function</h2> 
        <img class="grayscale_effect" 
             src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png" 
             alt="GeeksforGeeks logo"> 
</body>

</html>

Output:

Supported Browsers: The browsers supported by the grayscale() function are listed below:

  • Google Chrome 18.0
  • Microsoft Edge 12.0
  • Firefox 35.0
  • Safari 6.0
  • Opera 15.0

CSS grayscale() Function – FAQs

What does the grayscale() function do in CSS?

The grayscale() function is used with the filter property to convert an element’s colors to shades of gray, effectively removing its color saturation.

How do you apply the grayscale() function in CSS?

Apply the grayscale effect by using filter: grayscale(100%); on the desired element.

Can grayscale() be combined with other filter functions?

Yes, grayscale() can be combined with other filter functions like brightness() or contrast() to create complex visual effects.

Is the grayscale() function animatable in CSS?

Yes, you can animate the grayscale() effect using CSS animations or transitions, allowing the effect to change over time.

Does grayscale() affect performance in CSS?

Applying grayscale() on large images or many elements can have a slight impact on performance, especially on lower-end devices, due to increased rendering requirements.

Dive deep into the world of JavaScript with our JavaScript Full Course Online, offering everything from the basics to advanced techniques. Learn how to build interactive websites, optimize your code, and earn a certification to showcase your skills.

Take the Three 90 Challenge! Complete 90% of the course in 90 days, and earn a 90% refund. Push your limits and stay motivated as you work towards mastering JavaScript. Join now and get started on your JavaScript learning journey!


Next Article

Similar Reads

three90RightbarBannerImg