grayscale() CSS function - CSS | MDN
View originalCrawl details
- Current
Summary (TL;DR)
The grayscale() CSS filter function converts an image to black and white. It takes a number or percentage as the amount parameter. A value of 100% makes the image completely grayscale, 0% leaves it unchanged, and values in between apply a linear effect. The default value is 1 (fully grayscale). The filter works with other filter functions like blur(), brightness(), contrast(), and sepia() in the filter and backdrop-filter properties. Examples show valid usage: grayscale(0) for no effect, grayscale(.7) for 70% grayscale, and grayscale() as a shorthand for full grayscale. The formal syntax allows an optional number or percentage argument.
Try it
filter: grayscale(0);
filter: grayscale(0.2);
filter: grayscale(60%);
filter: grayscale(1);
<section id="default-example">
<img
class="transition-all"
id="example-element"
src="/shared-assets/images/examples/firefox-logo.svg"
width="200" />
</section>
Syntax
css
grayscale(amount)
Parameters
amountOptional-
Amount of the input image that is converted to grayscale. It is specified as a
<number>or a<percentage>. A value of100%changes the input completely to grayscale, while a value of0%leaves the input unchanged. Values between0%and100%have linear multipliers on the effect. The initial value used for interpolation is0. The default value is1.
Formal syntax
<grayscale()> =
grayscale( [ <number> | <percentage> ]? )
Examples
Examples of correct values for grayscale()
css
grayscale(0) /* No effect */
grayscale(.7) /* 70% grayscale */
grayscale() /* Completely grayscale */
grayscale(1)
grayscale(100%)
Specifications
| Specification |
|---|
| Filter Effects Module Level 1 # funcdef-filter-grayscale |
Browser compatibility
See also
The other <filter-function> functions available to be used in values of the filter and backdrop-filter properties include:
Help improve MDN
Was this page helpful to you?Yes No
This page was last modified on by MDN contributors.