Thursday, April 30, 2026

distinction() | CSS-Tips


The CSS distinction() filter perform will increase or decreases the distinction of a component, both making colours come out extra or dulling them to grey. In contrast to different filter features like brightness() or saturate()distinction() impacts each saturation and lightness, preserving solely the colour’s hue.

.low {
  filter: distinction(50%);
}

.regular {
  filter: distinction(100%);
}

.excessive {
  filter: distinction(200%);
}

The distinction() perform is outlined within the Filter Results Module Degree 1 specification.

Syntax

The official syntax for the distinction() perform is:

 = distinction( [  |  ]? )

Or just:

filter: distinction();

The distinction() perform is just suitable with the CSS filter and backdrop-filter properties.

Arguments

/* Utilizing percentages */
filter: distinction(0%); /* Completely grayed out */
filter: distinction(50%); /* Partially grayed out */
filter: distinction(100%); /* No change */
filter: distinction(150%); /* Ingredient is 1.5 instances extra outlined */

/* Utilizing numbers (0–1 vary) */
filter: distinction(0); /* Completely grayed out */
filter: distinction(0.5); /* Partially grayed out */
filter: distinction(1); /* No change */
filter: distinction(1.5); /* Ingredient is 1.5 instances extra outlined */

/* Utilizing percentages */
filter: distinction(0%); /* Completely grayed out */
filter: distinction(50%); /* Partially grayed out */
filter: distinction(100%); /* No change */
filter: distinction(150%); /* Ingredient is 1.5 instances extra outlined */

/* Utilizing numbers (0–1 vary) */
filter: distinction(0); /* Completely grayed out */
filter: distinction(0.5); /* Partially grayed out */
filter: distinction(1); /* No change */
filter: distinction(1.5); /* Ingredient is 1.5 instances extra outlined */

/* Works with CSS variables */
--amount: 200%;
filter: distinction(--amount);

/* No argument */
filter: distinction(); /* No change */

/* Unfavorable worth */
filter: distinction(-1.5); /* No impact */
filter: distinction(--amount);

/* No argument */
filter: distinction(); /* No change */

/* Unfavorable worth */
filter: distinction(-1.5); /* No impact */

The distinction() perform takes a single argument, which generally is a optimistic decimal or proportion worth. The argument determines the brand new distinction for the component, the place:

  • 0 or 0% dries out all distinction from the component, leading to a totally grey picture.
  • 1 or 100% leaves the component utterly unchanged.
  • Values above 1 or 100% improve the distinction linearly.

Unfavorable values aren’t allowed. However CSS variables are:

.component {
  --filter-amount: 150%;
  filter: distinction(var(--filter-amount));
}

How distinction() impacts shade

Like different filter features, the distinction() filter operates purely on RGB math. Particularly, given an  it multiplies every RGB channel by that  after which provides 255 * (0.5 - 0.5 * ) to the outcome. In follow, this impacts colours in one in every of two methods:

  • Excessive distinction (better than 1) makes mild pixels get lighter and darkish pixels get darker, so colours develop into extra vivid.
  • Low distinction (smaller than 1) pulls all pixels towards a center grey. This reduces the distinction between mild and darkish areas, making the picture look flat and muted.

Primary utilization

Some background photographs, often in hero sections or carousels, could make the foreground textual content troublesome to learn. Particularly if it has very brilliant and darkish colours, which compete with any textual content shade. To resolve this, we will use distinction() to scale back the distinction between the picture’s whites and blacks, making textual content extra readable in opposition to the entire picture.

img {
    filter: distinction(70%) brightness(60%);
}

The low distinction flattens the picture, and as a plus, we will additionally scale back the picture’s brightness to make the textual content pop no matter its colours.

Demo: Making product card photographs pop on hover

One other helpful utility for distinction() is to spotlight a picture in a person’s interplay. For instance, in a row of picture playing cards, we may improve the picture’s distinction and in addition scale it on hover

.card img {
  transition:
    filter 0.4s ease,
    rework 0.4s ease;
}

.card:hover img {
  filter: distinction(125%);
  rework: scale(1.05);
}

Is distinction() the identical as contrast-color()?

Whereas each CSS features have comparable names, they don’t seem to be to be confused with one another.

  • distinction() is a filter perform that makes a component extra vivid by making whites lighter and blacks darker.
  • contrast-color() returns the textual content shade with the very best distinction to a stable background. Its ensuing shade is both white or black, relying on which shade contrasts most with the background. It is usually not a filter perform.

Browser assist

The distinction() perform is at present supported throughout all fashionable browsers.

Related Articles

Latest Articles