CSS colors and opacity

Quick reference for CSS color syntax, alpha, currentColor, and how opacity differs from a transparent color and from hiding interaction.

This page is about how you write a color, how currentColor works, and how opacity differs from an alpha channel on one property. It is not a backgrounds page, and it is not a visibility or display: none discussion — those remain on the display page.

opacity multiplies the entire element’s used transparency, including descendants. A child cannot cancel a parent’s opacity by setting opacity: 1 or a solid color. The faded box still occupies space and, unless you also change pointer-events, can still receive pointer and hit-testing interaction. Opacity is not a way to hide a control.

An alpha component on color or background-color affects only that paint. currentColor resolves to the element’s computed color, so a border or accent can follow the text color without repeating the value.

Examples were parsed for syntax and structure. Contrast, compositing, and pointer hit-testing were not measured in a browser.

Official sources: MDN and the CSS specification. Fragments were checked with PostCSS 8 for syntax and structure. That is not a CSS conformance suite, and this is not a browser render or visual test.

CSS reference catalog → · CSS tutorial overview →

Color syntax, alpha, and currentColor

Modern CSS accepts hex (#rgb, #rrggbb, #rrggbbaa), the functional notations rgb(), hsl(), and newer spaces such as lab(), lch(), and oklch(), plus named colors and the keywords currentColor, transparent, and Canvas / system colors. Space-separated rgb(11 88 83 / 0.2) is the current function syntax; the older rgb() / rgba() comma form still works. color-mix() and some wide-gamut spaces have uneven support and are noted here as a compatibility limit, not demonstrated as if every engine agreed.

transparent is a fully transparent color. In older interpolation it behaved like transparent black, which can produce unexpected grey in some gradient mid-stops. currentColor is a keyword that tracks the used color, not a second palette.

Syntax or propertyInitial / defaultInheritedApplies toNotes
colordepends on the user agentyesall elements and textSets the text (and currentColor) color. Common values: #0B5853, rgb(11 88 83 / 0.8), hsl(174 78% 19%), currentColor, inherited keywords. It is inherited, unlike opacity.
currentColorthe used value of colorn/a (keyword)any property that accepts a colorResolves to the element’s computed color. Commonly used for border-color, box-shadow, fill in SVG, or an accent that should follow the text. It is not a custom property; changing color updates it.
transparentfully transparentn/a (keyword)any property that accepts a colorEquivalent to a fully transparent color. Prefer a specific rgb() / hsl() with zero alpha when interpolation in a gradient matters. Do not use it to disable a control.

Alpha on a color and currentColor

color: #0B5853;
background: rgb(11 88 83 / 0.2);
border: 2px solid currentColor;

A translucent background uses an alpha channel on that color. The border follows the text color through currentColor.

  • No extra opacity is set here, so descendants would not be forced to fade with the element as a group.
html
<p class="swatch">Current color and a translucent background</p>
<style>
.swatch {
  color: #0B5853;
  background: rgb(11 88 83 / 0.2);
  border: 2px solid currentColor;
  padding: 0.5rem 0.75rem;
  font-family: sans-serif;
}
</style>

What this markup means

The text color is #0B5853. The background uses the same hue with 0.2 alpha, which paints only the background translucently. border-color is currentColor, so the border follows the text color without repeating the hex value. The page does not apply opacity on .swatch.

Related: Backgrounds, Borders

MDN documentation → · CSS specification →

opacity is not a transparent color, and it does not hide interaction

opacity is a separate property whose initial value is 1. It is not inherited, but it still affects descendants because they are painted as part of the element’s group. Setting opacity: 0.4 on a parent, then opacity: 1 or a solid background on a child, does not restore a fully opaque child.

opacity: 0 leaves the box in the layout and, by default, still targetable with the pointer. That is different from a transparent background (the text can remain solid and hittable), from visibility: hidden (the box is invisible but still occupies space, and a visible descendant can show), and from display: none (the box is not laid out). Use opacity for a fade, not as the only mechanism to “turn off” a button.

Syntax or propertyInitial / defaultInheritedApplies toNotes
opacity1noall elementsA number from 0 to 1 (or a percentage in current CSS). It fades the entire element, including descendants, and creates a stacking context when the value is not 1. It does not remove the box from layout or, by itself, from pointer events. Children cannot opt out.

A child cannot undo a parent opacity

.faded { opacity: 0.4; }
.faded .solid { opacity: 1; color: #0B5853; }

The parent opacity applies to the group. The child’s opacity: 1 and solid color do not cancel that fade, and the faded control remains in the tree.

  • No pointer-events: none is set. Opacity alone should not be documented as hiding interaction. Hit-testing was not run in a browser.
html
<div class="faded">
  <p>Faded parent</p>
  <button type="button" class="solid">Child still in the group</button>
</div>
<style>
.faded { opacity: 0.4; font-family: sans-serif; }
.faded .solid { opacity: 1; color: #0B5853; background: #ffffff; }
</style>

What this markup means

.faded sets opacity: 0.4 on the whole group. The button then sets opacity: 1 and a solid background, which does not lift it out of the parent’s opacity group. The button is still laid out and is not hidden from interaction by these rules. Compare that with a translucent background-color on a single element, which would not fade the text unless the text color also had alpha.

Related: Display (none vs visibility), Backgrounds

MDN documentation → · CSS specification →