惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
M
MIT News - Artificial intelligence
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
F
Fortinet All Blogs
L
LangChain Blog
D
Docker
G
Google Developers Blog
B
Blog RSS Feed
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
I
InfoQ
博客园 - 【当耐特】
The Cloudflare Blog
P
Proofpoint News Feed
GbyAI
GbyAI
博客园 - 司徒正美
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Jina AI
Jina AI
量子位
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
有赞技术团队
有赞技术团队
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
大猫的无限游戏
大猫的无限游戏
F
Full Disclosure
雷峰网
雷峰网
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

CSS-Tricks

pointer-events | CSS-Tricks What’s !important #15: Boundary-aware CSS, Time-based CSS, Full-bleed CSS, and More | CSS-Tricks Get Ready For the Powerful CSS border-shape Property! | CSS-Tricks What’s !important #14: Gap Decorations, random(), <select> field sizing, and More | CSS-Tricks The Shifting Line Between CSS States and JavaScript Events | CSS-Tricks translateZ() | CSS-Tricks translateY() | CSS-Tricks translateX() | CSS-Tricks translate() | CSS-Tricks Using Scroll-Driven Animations for Opposing Scroll Directions | CSS-Tricks A First Look at Scroll-Triggered Animations | CSS-Tricks The Siren Song of  ariaNotify() | CSS-Tricks Prop For That | CSS-Tricks What’s !important #13: @function, alpha(), CSS Wordle, and More | CSS-Tricks There’s no need to include ‘navigation’ in your navigation labels | CSS-Tricks Why Isn't My 3D View Transition Working? | CSS-Tricks Creating Memorable Web Experiences: A Modern CSS Toolkit | CSS-Tricks Scroll-Driven, Scroll-Triggered, Scroll States, and View Transitions | CSS-Tricks Another Stab at the Perfect CSS Pie Chart... Sans JavaScript! | CSS-Tricks offset-path | CSS-Tricks @custom-media | CSS-Tricks @function | CSS-Tricks ::search-text | CSS-Tricks Astro Markdown Component Utility for Any Framework | CSS-Tricks What’s !important #12: Safari Testing, ::checkmark, HTML Anchor Positioning, and More | CSS-Tricks Revealing Text With CSS letter-spacing | CSS-Tricks Technical Writing in the AI Age | CSS-Tricks Cross-Document View Transitions: Scaling Across Hundreds of Elements | CSS-Tricks The State of CSS Centering in 2026 | CSS-Tricks Stack Overflow: When We Stop Asking | CSS-Tricks Cross-Document View Transitions: The Gotchas Nobody Mentions | CSS-Tricks What’s !important #11: 3D Voxel Scenes, Flying Focus, CSS Syntaxes, and More | CSS-Tricks Computing and Displaying Discounted Prices in CSS | CSS-Tricks rotateX() | CSS-Tricks rotateY() | CSS-Tricks rotateZ() | CSS-Tricks rotate() | CSS-Tricks Soon We Can Finally Banish JavaScript to the ShadowRealm | CSS-Tricks Using CSS corner-shape For Folded Corners | CSS-Tricks contrast-color() | CSS-Tricks hypot() | CSS-Tricks saturate() | CSS-Tricks justify-self | CSS-Tricks
contrast() | CSS-Tricks
Gabriel Shoy · 2026-04-29 · via CSS-Tricks

The CSS contrast() filter function increases or decreases the contrast of an element, either making colors pop out more or dulling them to gray. Unlike other filter functions like brightness() or saturate()contrast() affects both saturation and lightness, keeping only the color’s hue.

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

.normal {
  filter: contrast(100%);
}

.high {
  filter: contrast(200%);
}

The contrast() function is defined in the Filter Effects Module Level 1 specification.

Syntax

The official syntax for the contrast() function is:

<contrast()> = contrast( [ <number> | <percentage> ]? )

Or simply:

filter: contrast(<amount>);

The contrast() function is only compatible with the CSS filter and backdrop-filter properties.

Arguments

/* Using percentages */
filter: contrast(0%); /* Totally grayed out */
filter: contrast(50%); /* Partially grayed out */
filter: contrast(100%); /* No change */
filter: contrast(150%); /* Element is 1.5 times more defined */

/* Using numbers (0–1 range) */
filter: contrast(0); /* Totally grayed out */
filter: contrast(0.5); /* Partially grayed out */
filter: contrast(1); /* No change */
filter: contrast(1.5); /* Element is 1.5 times more defined */

/* Using percentages */
filter: contrast(0%); /* Totally grayed out */
filter: contrast(50%); /* Partially grayed out */
filter: contrast(100%); /* No change */
filter: contrast(150%); /* Element is 1.5 times more defined */

/* Using numbers (0–1 range) */
filter: contrast(0); /* Totally grayed out */
filter: contrast(0.5); /* Partially grayed out */
filter: contrast(1); /* No change */
filter: contrast(1.5); /* Element is 1.5 times more defined */

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

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

/* Negative value */
filter: contrast(-1.5); /* No effect */
filter: contrast(--amount);

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

/* Negative value */
filter: contrast(-1.5); /* No effect */

The contrast() function takes a single argument, which can be a positive decimal or percentage value. The argument determines the new contrast for the element, where:

  • 0 or 0% dries out all contrast from the element, resulting in a completely gray image.
  • 1 or 100% leaves the element completely unchanged.
  • Values above 1 or 100% increase the contrast linearly.

Negative values aren’t allowed. But CSS variables are:

.element {
  --filter-amount: 150%;
  filter: contrast(var(--filter-amount));
}

How contrast() affects color

Like other filter functions, the contrast() filter operates purely on RGB math. Specifically, given an <amount> it multiplies each RGB channel by that <amount> and then adds 255 * (0.5 - 0.5 * <amount>) to the result. In practice, this affects colors in one of two ways:

  • High contrast (greater than 1) makes light pixels get lighter and dark pixels get darker, so colors become more vivid.
  • Low contrast (smaller than 1) pulls all pixels toward a middle gray. This reduces the difference between light and dark areas, making the image look flat and muted.

Basic usage

Some background images, usually in hero sections or carousels, can make the foreground text difficult to read. Especially if it has very bright and dark colors, which compete with any text color. To solve this, we can use contrast() to reduce the difference between the image’s whites and blacks, making text more readable against the whole image.

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

The low contrast flattens the image, and as a plus, we can also reduce the image’s brightness to make the text pop regardless of its colors.

Demo: Making product card images pop on hover

Another useful application for contrast() is to highlight an image in a user’s interaction. For example, in a row of image cards, we could increase the image’s contrast and also scale it on hover

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

.card:hover img {
  filter: contrast(125%);
  transform: scale(1.05);
}

Is contrast() the same as contrast-color()?

While both CSS functions have similar names, they are not to be confused with each other.

  • contrast() is a filter function that makes an element more vivid by making whites lighter and blacks darker.
  • contrast-color() returns the text color with the highest contrast to a solid background. Its resulting color is either white or black, depending on which color contrasts most with the background. It is also not a filter function.

Browser support

The contrast() function is currently supported across all modern browsers.