Languages
[Edit]
EN

CSS - grayscale filter

0 points
Created by:
Laylah-Walsh
294

In this article, we would like to show you how to use the grayscale filter in CSS​​​​​​.

Quick solution:

.grayscale {
  filter: grayscale(100%);
}

.half-grayscale {
  filter: grayscale(0.5);
}

 

Practical example

In this example, we present how to use the grayscale filter with percentage and fractional values.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>
    
    body {
      display: flex;
    }
    
    img {
      height: 100px;
      margin: 5px;
    }

    .grayscale {
      filter: grayscale(100%);  /*		<----- grayscale 100%   */
    }
    
    .half-grayscale {
      filter: grayscale(0.5);  /*		<----- grayscale 50%  	*/
    }

  </style>
</head>
<body>
  <img class="grayscale" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
  <img class="half-grayscale" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
  <img src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
</body>
</html>

Result:

CSS - grayscale filter example
CSS - grayscale filter example

 

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join