CSS contrast() Function
Example
Increase and decrease the contrast for an image:
#img1 {
filter: contrast(150%);
}
#img2 {
filter:
contrast(50%);
}
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The CSS contrast()
filter function adjusts the
contrast of an element.
- 0% will make the image completely gray
- 100% (1) is default and represents the original image
- Values over 100% increases the contrast
- Values under 100% decreases the contrast
Version: | CSS Filter Effects Module Level 1 |
---|
Browser Support
The numbers in the table specify the first browser version that fully supports the function.
Function | |||||
---|---|---|---|---|---|
contrast() | 18 | 12 | 35 | 6 | 15 |
CSS Syntax
contrast(amount)
Value | Description |
---|---|
amount | Optional. Specifies the contrast as a number or percent. 0% will make the element completely gray. 100% (1) is default and represents the original image (no effect). Values over 100% increases the contrast. Values under 100% decreases the contrast. |
More Examples
Example
Use contrast() with the backdrop-filter property:
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 »
Related Pages
CSS reference: CSS filter property.
CSS reference: CSS blur() function.
CSS reference: CSS brightness() function.
CSS reference: CSS drop-shadow() function.
CSS reference: CSS grayscale() function.
CSS reference: CSS hue-rotate() function.
CSS reference: CSS invert() function.