How to convert an image to grayscale in HTML/CSS?

Spread the love

To convert an image to grayscale in HTML/CSS, we set the filter property.

For instance, we write

<img src="" />

to add an img element.

Then we write

img {
  -webkit-filter: grayscale(1);
  filter: grayscale(1);

to set the filter and -webkit-filter property to grayscale(1) to make the image grayscale.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *