offline version v3


83 of 298 menu

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 blur function
    that blurs a background
  • the brightness function
    that sets a background brightness
  • the drop-shadow function
    that sets a background shadow
  • the hue-rotate function
    that sets a background hue
  • the invert function
    that inverts background colors
  • the opacity function
    that sets a background opacity
  • the sepia function
    that converts a background to sepia
  • the background property
    that is a shorthand property for a background
  • the background-image property
    with that you can set a background image for a block
  • the filter property
    that sets a background style
enru