CSS Data Type - <filter-function>



The CSS data type <filter-function> signifies a graphical effect, which changes the appearance of an input image. This data type is used in the filter and backdrop-filter properties of CSS.

Possible values

The data type <filter-function> is defined using one of the following filter functions, where each function needs an argument to be passed. In case the argument is invalid, no filter will be applied.

  • blur(): Image is blurred.

  • brightness(): Image is made brighter or darker.

  • contrast(): Image's contrast is increased or decreased.

  • drop-shadow(): A drop shadow is applied behind the image.

  • grayscale(): Image converted to grayscale.

  • hue-rotate(): Hue of the image is changed.

  • invert(): Colors of the image is inverted.

  • opacity(): Image is made transparent.

  • saturate(): Input image is super-saturated or desaturated.

  • sepia(): Image is converted to sepia.

Syntax

<filter-function> = <blur()> | <brightness()> | <contrast()> | <drop-shadow()> | <grayscale()> | <hue-rotate()> | <invert()> | <opacity()> | <saturate()> | <sepia()>

CSS <filter-function> - Blurring an image

The following example demonstrates the use of blur() filter function to blur an image:

<html>
<head>
<style>
   .blur-image {
      filter: blur(8px);
   }
   .box {
      background: url(images/orange-flower.jpg) no-repeat center;
      width: 200px;
      height: 200px;
   }
</style>
</head>
<body>
   <h2><filter-function> - blur()</h2>
   <p>No blur</p>
   <div class="box"></div>
   <p>Blurred</p>
   <div class="box blur-image"></div>
</body>
</html>

CSS <filter-function> - Brightening an image

The following example demonstrates the use of brightness() filter function to increase or decrease the brightness of an image:

<html>
<head>
<style>
   .bright-image-inc{
      filter: brightness(180%);
   }

   .bright-image-dec {
      filter: brightness(50%);
   }

   .box {
      background: url(images/orange-flower.jpg) no-repeat center;
      width: 200px;
      height: 200px;
   }
</style>
</head>
<body>
   <h2><filter-function> - brightness()</h2>
   <p>Normal</p>
   <div class="box"></div>
   <p>Brightness Increased</p>
   <div class="box bright-image-inc"></div>
   <p>Brightness Decreased</p>
   <div class="box bright-image-dec"></div>
</body>
</html>

CSS <filter-function> - Changing the contrast of an image

The following example demonstrates the use of contrast() filter function to change the contrast of an image:

<html>
<head>
<style>
   .contrast-image-inc{
      filter: contrast(250%);
   }

   .contrast-image-dec {
      filter: contrast(25%);
   }

   .box {
      background: url(images/red-flower.jpg) no-repeat center;
      width: 200px;
      height: 200px;
   }
</style>
</head>
<body>
   <h2><filter-function> - contrast()</h2>
   <p>Normal</p>
   <div class="box"></div>
   <p>Contrast Increased</p>
   <div class="box contrast-image-inc"></div>
   <p>Contrast Decreased</p>
   <div class="box contrast-image-dec"></div>
</body>
</html>

For more examples of filter functions, refer the filter page.

Advertisements