contrast function
The contrast function allows you to change
a contrast of a background image. The initial
background contrast is determined by the 100%
value or 1; as they decrease, the image
contrast also decreases. Accordingly, when the
value increases more than 100%, the
contrast increases. Negative values are not
applied, and an empty value is automatically
treated as 1.
Syntax
selector {
filter: contrast(number);
}
Example
Let's set the contrast for
our image to 20%:
<div id="elem"></div>
#elem {
filter: contrast(20%);
background: url("bg.png") center / cover no-repeat;
width: 400px;
height: 300px;
border: 1px solid black;
}
:
Example
Now let's increase the contrast of
the image to 120%:
<div id="elem"></div>
#elem {
filter: contrast(120%);
background: url("bg.png") center / cover no-repeat;
width: 400px;
height: 300px;
border: 1px solid black;
}
:
Example
Let's set our image to its original contrast:
<div id="elem"></div>
#elem {
filter: contrast(1);
background: url("bg.png") center / cover no-repeat;
width: 400px;
height: 300px;
border: 1px solid black;
}
:
See also
-
the
blurfunction
that blurs a background -
the
brightnessfunction
that sets a background brightness -
the
drop-shadowfunction
that sets a background shadow -
the
hue-rotatefunction
that sets a background hue -
the
invertfunction
that inverts background colors -
the
opacityfunction
that sets a background opacity -
the
sepiafunction
that converts a background to sepia -
the
backgroundproperty
that is a shorthand property for a background -
the
background-imageproperty
with that you can set a background image for a block -
the
filterproperty
that sets a background style