2 properties, 1 at-rule, 17 functions, 8 types defined by this
specification, 22 of them known to at least one browser
(the others are badged Not in any browser yet).
PropertyBaseline: widely availablesince January 2018
MDN The opacityCSS property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency.
<section class="default-example" id="default-example"> <p id="example-element"> London. Michaelmas term lately over, and the Lord Chancellor sitting in Lincoln's Inn Hall. Implacable November weather. As much mud in the streets as if the waters had but newly retired from the face of the earth, and it would not be wonderful to meet a Megalosaurus, forty feet long or so, waddling like an elephantine lizard up Holborn Hill. </p></section>
Syntax
<opacity-value>
Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition
Initial
1
Applies to
all elements
Inherited
no
Percentages
map to the range [0,1]
Computed value
specified number, clamped to the range [0,1]
Canonical order
per grammar
Animation type
by computed value type
Browser support
First browser version supporting opacity
Chrome
1
Edge
12
Firefox
1
Safari
2
Chrome Android
18
Safari iOS
1
First version with support, from MDN browser-compat-data.
MDN The alpha()CSSfunction takes an origin color and returns that same color with a modified alpha (transparency) channel. The color components of the origin color are preserved unchanged. The result is in the same color space as the origin color.
Live previewExample from MDN
:root { --my-color: oklch(60% 0.25 315 / 0.3); /* Same color, but with alpha set to 80% */ --my-color-80: alpha(from var(--my-color) / 80%);}.box1 { background-color: var(--my-color);}.box2 { background-color: var(--my-color-80);}body { font-family: sans-serif; display: flex; gap: 10%; justify-content: center;}div { width: 40%; height: 100px; display: flex; justify-content: center; align-items: center;}
MDN The color-mix() functional notation takes one or more <color> values and returns the result of mixing them in a given colorspace by a given amount.
MDN The color() functional notation allows a color to be specified in a particular, specified color space rather than the implicit sRGB color space that most of the other color functions operate in.
Spec The contrast-color() functional notation identifies a sufficiently contrasting color against a specified background or foreground color without requiring manual computation.
MDN The contrast-color()CSSfunction takes a color value and returns a contrasting color. The function commonly ensures the WCAG AA minimum contrast. The browsers may use different and better algorithms.
Live previewExample from MDN
:root { --button-color: lightblue;}button { background-color: var(--button-color); /* Set contrasting text color automatically */ color: contrast-color(var(--button-color));}body { padding: 1rem;}button { margin: 3rem; padding: 1rem; width: 150px; font-size: 2rem; border-radius: 1rem;}@supports not (color: contrast-color(red)) { body::before { content: "Your browser doesn't support the contrast-color() function."; background-color: wheat; display: block; text-align: center; padding: 1rem 0; }}
<label> Select background color of the button: <input type="color" id="colorPicker" value="#660066" /></label><br /><button>Button</button>
MDN The device-cmyk() functional notation is used to express CMYK colors in a device dependent way, specifying the cyan, magenta, yellow, and black components.
MDN The hsl() functional notation expresses a color in the sRGBcolor space according to its hue, saturation, and lightness components. An optional alpha component represents the color's transparency.
MDN The hwb() functional notation expresses a color in the sRGBcolor space according to its hue, whiteness, and blackness. An optional alpha component represents the color's transparency.
MDN The lch() functional notation expresses a given color using the LCH color space, which represents lightness, chroma, and hue. It uses the same L axis as the lab() color function of the CIELab color space, but it uses the polar coordinates C (Chroma) and H (Hue).
MDN The light-dark()CSSfunction accepts two colors or two images and returns a color or an image based on the active color scheme, without needing a prefers-color-schememedia feature.
Live previewExample from MDN
:root { /* this has to be set to switch between light or dark */ color-scheme: light dark; --light-bg: ghostwhite; --light-color: darkslategray; --light-code: tomato; --dark-bg: darkslategray; --dark-color: ghostwhite; --dark-code: gold;}* { background-color: light-dark(var(--light-bg), var(--dark-bg)); color: light-dark(var(--light-color), var(--dark-color));}code { color: light-dark(var(--light-code), var(--dark-code));}.light { /* forces light color-scheme */ color-scheme: light;}.dark { /* forces dark color-scheme */ color-scheme: dark;}section { padding: 0.8rem;}
<h1><code>light-dark()</code> CSS function</h1><section> <h2>Automatic</h2> <p>This section will react to the users system or user agent setting.</p></section><section class="light"> <h2>Light</h2> <p> This section will be light due to the <code>color-scheme: light;</code>. </p></section><section class="dark"> <h2>Dark</h2> <p>This section will be dark due to the <code>color-scheme: dark;</code>.</p></section>
Syntax
<light-dark-color> | <light-dark-image>
Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Browser support
First browser version supporting light-dark()
Chrome
123
Edge
123
Firefox
120
Safari
17.5
Chrome Android
123
Safari iOS
17.5
First version with support, from MDN browser-compat-data.
MDN The oklch() functional notation expresses a given color in the Oklab color space. oklch() is the cylindrical form of oklab(), using the same L axis, but with polar Chroma (C) and Hue (h) coordinates.
MDN The rgb() functional notation expresses a color in the sRGBcolor space according to its red, green, and blue components. An optional alpha component represents the color's transparency.
MDN The <color-interpolation-method>CSSdata type represents the color space used for interpolation between <color> values. It can be used to override the default interpolation color space for color-related functional notations such as color-mix() and linear-gradient().
Spec Colors in CSS are represented by the <color> type:
MDN The <color>CSSdata type represents a color. A <color> may also include an alpha-channeltransparency value, indicating how the color should composite with its background.
Live previewExample from MDN
div { height: 200px; width: 200px;}
<div></div><hr /><label for="color">Enter a valid color value:</label><input type="text" id="color" />
Spec The syntax of a <hex-color> is a <hash-token> token whose value consists of 3, 4, 6, or 8 hexadecimal digits. In other words, a hex color is written as a hash character, "#", followed by some number of digits 0-9 or letters a-f (the case of the letters doesn’t matter - #00ff00 is identical to #00FF00).
MDN The <hex-color>CSSdata type is a notation for describing the hexadecimal color syntax of an sRGB color using its primary color components (red, green, blue) written as hexadecimal numbers, as well as its transparency.
MDN The <hue-interpolation-method>CSSdata type represents the algorithm used for interpolation between hue values. The interpolation method specifies how to find a midpoint between two hue values based on a color wheel. It is used as a component of the <color-interpolation-method> data type.
Live previewExample from MDN
div { border: 1px solid black; height: 50px; margin: 10px; width: 90%;}p { color: white; margin: 6px;}/* Fallback styles */.hsl,.hsl-shorter,.hsl-named { background: linear-gradient( to right, hsl(39 100% 50%), hsl(46 100% 50%), hsl(53 100% 50%), hsl(60 100% 50%) );}.hsl-increasing { background: linear-gradient( to right, hsl(190 100% 50%), hsl(225 100% 50%), hsl(260 100% 50%), hsl(295 100% 50%), hsl(330 100% 50%), hsl(365 100% 50%), hsl(400 100% 50%), hsl(435 100% 50%), hsl(470 100% 50%), hsl(505 100% 50%), hsl(540 100% 50%) );}.hsl-decreasing,.hsl-longer,.hsl-named-longer { background: linear-gradient( to right, hsl(399 100% 50%), hsl(368 100% 50%), hsl(337 100% 50%), hsl(307 100% 50%), hsl(276 100% 50%), hsl(245 100% 50%), hsl(214 100% 50%), hsl(183 100% 50%), hsl(152 100% 50%), hsl(122 100% 50%), hsl(91 100% 50%), hsl(60 100% 50%) );}.hsl { background: linear-gradient( to right in hsl, hsl(39deg 100% 50%), hsl(60deg 100% 50%) );}.hsl-increasing { background: linear-gradient( to right in hsl increasing hue, hsl(190deg 100% 50%), hsl(180deg 100% 50%) );}.hsl-decreasing { background: linear-gradient( to right in hsl decreasing hue, hsl(39deg 100% 50%), hsl(60deg 100% 50%) );}.hsl-shorter { background: linear-gradient( to right in hsl shorter hue, hsl(39deg 100% 50%), hsl(60deg 100% 50%) );}.hsl-longer { background: linear-gradient( to right in hsl longer hue, hsl(39deg 100% 50%), hsl(60deg 100% 50%) );}.hsl-named { background: linear-gradient(to right in hsl, orange, yellow);}.hsl-named-longer { background: linear-gradient(to right in hsl longer hue, orange, yellow);}
MDN The <hue>CSSdata type represents the hue angle of a color. It is used in the color functions that accept hue expressed as a single value, specifically hsl(), hwb(), lch(), and oklch() functional notations.
Spec CSS defines a large set of named colors, so that common colors can be written and read more easily. A <named-color> is written as an <ident>, accepted anywhere a <color> is. As usual for CSS-defined <ident>s, all of these keywords are ASCII case-insensitive.
MDN The <named-color>CSSdata type is the name of a color, such as red, blue, black, or lightseagreen. Syntactically, a <named-color> is an ident.
Spec However, in forced colors mode, most colors on the page are forced into a restricted, user-chosen palette, see CSS Color Adjustment 1 § 5.2 Forced Colors Mode Color Palettes. The <system-color> keywords expose these user-chosen colors so that the rest of the page can integrate with this restricted palette.
MDN The <system-color>CSSdata type usually reflects the default color choices used for the different parts of a web page.
Live previewExample from MDN
.button { border: 0; padding: 10px; box-shadow: -2px -2px 5px gray, 2px 2px 5px gray;}@media (forced-colors: active) { .button { /* Use a border instead, since box-shadow is forced to 'none' in forced-colors mode */ border: 2px ButtonBorder solid; }}