CSS grayscale() function

Definition and usage

CSS's grayscale() The filter function converts the image to grayscale.

  • 100% (or 1) will make the image completely grayscale
  • 0% (or 0) has no effect

Example

Example 1

Set different grayscale values for images:

#img1 {
  filter: grayscale(1);
}
#img2 {
  filter: grayscale(60%);
}
#img3 {
  filter: grayscale(0.4);
}

Try it yourself

Example 2

to grayscale() with backdrop-filter Combined use of properties:

div.transbox {
  background-color: rgba(255, 255, 255, 0.4);
  -webkit-backdrop-filter: grayscale(50%);
  backdrop-filter: grayscale(50%);
  padding: 20px;
  margin: 30px;
  font-weight: bold;
}

Try it yourself

CSS Syntax

grayscale(amount)
Value Description
amount

Optional. Specify the grayscale value, which can be a number or a percentage.

100% (or 1) will make the element completely grayscale.

0% (or 0) represents the original image (no effect).

The default value is 1.

Technical details

Version: CSS Filter Effects Module Level 1

Browser support

The numbers in the table represent the first browser version to fully support this function.

Chrome Edge Firefox Safari Opera
18 12 35 6 15

Related pages

Reference:CSS filter property

Reference:CSS blur() function

Reference:CSS brightness() function

Reference:CSS contrast() function

Reference:CSS drop-shadow() function

Reference:CSS hue-rotate() function

Reference:CSS invert() function

Reference:CSS opacity() function

Reference:CSS saturate() function

Reference:CSS sepia() function