CSS contrast() function

Definition and usage

CSS's contrast() Filter functions are used to adjust the contrast of elements.

  • 0% will make the image completely gray
  • 100% (or 1) is the default value, indicating the original image
  • Values over 100% will increase contrast
  • Values below 100% will decrease contrast

Example

Example 1

Increase and decrease the contrast of the image:

#img1 {
  filter: contrast(150%);
}
#img2 {
  filter: contrast(50%);
}

Try it yourself

Example 2

to contrast() with backdrop-filter Use attributes together:

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

Try it yourself

CSS syntax

contrast(amount)
Value Description
amount

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

0% will make the element completely gray.

100% (or 1) is the default value, indicating the original image (no effect).

Values over 100% increase contrast, while values below 100% decrease contrast.

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 attribute

Reference:CSS blur() function

Reference:CSS brightness() function

Reference:CSS drop-shadow() function

Reference:CSS grayscale() function

Reference:CSS hue-rotate() function

Reference:CSS invert() function

Reference:CSS opacity() function

Reference:CSS saturate() function

Reference:CSS sepia() function