Nebula icon indicating copy to clipboard operation
Nebula copied to clipboard

Use the CSS color-contrast property when it becomes available [🟥 awaiting full support]

Open chrisblakley opened this issue 2 years ago • 2 comments

This CSS property will handle proper color contrast based on given colors and AA/AAA compliance. Super cool and replaces the need for the Nebula Sass mixin that relies on 3 separate server-side functions for luminance and color contrast.

https://caniuse.com/mdn-css_types_color_color-contrast

No browsers currently fully support, but rumor is by the end of the year we'll be able to use it...

Screen Shot 2022-05-18 at 10 45 54 PM

Screen Shot 2022-05-18 at 10 46 10 PM

chrisblakley avatar May 19 '22 02:05 chrisblakley

https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-contrast Draft spec: https://drafts.csswg.org/css-color-5/#colorcontrast

Examples:

First color is the background color, and the rest are potential candidates to use. If none of the candidates work, it will default to either black or white.

color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)

color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)

chrisblakley avatar May 19 '22 16:05 chrisblakley

https://caniuse.com/mdn-css_types_color_color-contrast

Screen Shot 2024-01-24 at 10 57 50 AM

chrisblakley avatar Jan 24 '24 15:01 chrisblakley