Skip to main content

CSS Filters

Visual effects such as blur and saturation reach elements through the CSS filter property.

It accepts these filter functions:

  • blur()
  • brightness()
  • contrast()
  • drop-shadow()
  • grayscale()
  • hue-rotate()
  • invert()
  • opacity()
  • saturate()
  • sepia()

The CSS blur() Function

Elements are blurred by the blur() filter function, and the blur grows along with the value.

Without a value it falls back to 0, which has no effect.

Example

Two different strengths of blur on <img> elements:

Prompt
Create an HTML page that applies different CSS blur filter effects to two images. The first image should have a 2px blur and the second a 6px blur using the CSS filter property.
Output: complete HTML page

The CSS brightness() Function

How bright an element looks is controlled by the brightness() filter function.

  • 0% turns the image completely black
  • Anything under 100% darkens the image
  • 100% is the default and keeps the original brightness
  • Anything over 100% brightens the image

Example

One image rendered both brighter and darker than the original:

Prompt
Create an HTML page that adjusts the brightness of two images using the CSS filter property. The first image should be brighter at 150% and the second darker at 50%.
Output: complete HTML page

The CSS contrast() Function

Raising or lowering the contrast of an element is the role of the contrast() filter function.

  • 0% leaves the image completely gray
  • Below 100% the contrast drops
  • 100% is the default and keeps the original contrast
  • Above 100% the contrast rises

Example

An image with its contrast pushed up, and again with it pulled down:

Prompt
Create an HTML page that adjusts the contrast of two images using the CSS filter property. The first image should have increased contrast at 150% and the second decreased contrast at 50%.
Output: complete HTML page

The CSS drop-shadow() Function

To give an image a drop-shadow effect, reach for the drop-shadow() filter function.

Example

Two different drop-shadow effects on the same image:

Prompt
Create an HTML page that applies different CSS drop-shadow filter effects to two images. The first should have a gray drop shadow (8px 8px 10px) and the second a lightblue drop shadow (10px 10px 7px).
Output: complete HTML page

The CSS grayscale() Function

Turning an image gray is the job of the grayscale() filter function.

  • 0% (or 0) leaves the image unchanged
  • 100% (or 1) gives a completely grayscale image

Example

The same image at several levels of grayscale:

Prompt
Create an HTML page that applies different grayscale filter effects to three images using the CSS filter property. Use values of 1, 60%, and 0.4 respectively.
Output: complete HTML page

The CSS hue-rotate() Function

With the hue-rotate() filter function, the colors of an element rotate around the color circle.

Its value is the number of degrees to adjust the image by. At 0deg you see the original image, positive values raise the hue, and negative values lower it.

Example

The same image at several color rotations:

Prompt
Create an HTML page that applies different hue-rotate filter effects to three images using the CSS filter property. Use values of 200deg, 90deg, and -90deg respectively.
Output: complete HTML page

The CSS invert() Function

Use the invert() filter function to reverse the colors of an image.

  • 0% (or 0) leaves the image unchanged
  • 100% (or 1) inverts the colors fully

Example

Three levels of color inversion on one image:

Prompt
Create an HTML page that applies different invert filter effects to three images using the CSS filter property. Use values of 0.3, 70%, and 100% respectively.
Output: complete HTML page

The CSS opacity() Function

Making an element partly or fully see-through is what the opacity() filter function does.

  • 0% (or 0) leaves the element completely transparent
  • 50% (or 0.5) leaves the element 50% transparent
  • 100% (or 1) leaves the element unchanged

Example

The same image at several levels of opacity:

Prompt
Create an HTML page that applies different opacity filter effects to three images using the CSS filter property. Use values of 80%, 50%, and 0.2 respectively.
Output: complete HTML page

The CSS saturate() Function

Color intensity, or saturation, is what the saturate() filter function adjusts on an element.

  • 0% (or 0) removes the saturation completely
  • 100% (or 1) leaves the element unchanged
  • 200% (or 2) produces a super saturated element

Example

The same image at several levels of saturation:

Prompt
Create an HTML page that applies different saturation filter effects to three images using the CSS filter property. Use values of 0, 100%, and 200% respectively.
Output: complete HTML page

The CSS sepia() Function

A sepia tone is a warmer, more brown/yellow color, and the sepia() filter function gives it to an image.

  • 0% (or 0) leaves the image unchanged
  • 100% (or 1) gives the full sepia effect

Example

The same image at several levels of sepia:

Prompt
Create an HTML page that applies different sepia filter effects to three images using the CSS filter property. Use values of 1, 60%, and 0.4 respectively.
Output: complete HTML page