Custom Properties and Cascade Layers

W3C CSS Snapshot 2026

Reuse values with custom properties. Use cascade layers to set the priority of groups of rules.

On this page

Reuse values with custom properties

A custom property is a value you name yourself. Names start with --. :root matches the root element so descendants can inherit the value. var(--accent, teal) reads that value and uses teal as a fallback if the custom property is missing.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Reuse values with custom properties</title>
  <style>
    :root { --accent: purple; }
    .notice { color: var(--accent, teal); }
  </style>
</head>
<body>
<p class="notice">Your order is ready.</p>
<p>Your package is on the way.</p>
</body>
</html>

What to expect The first paragraph is purple. Delete the --accent declaration to make it teal.

Order groups of rules with @layer

A cascade layer is a named priority group. With normal declarations in the same origin, a later layer wins over an earlier layer before specificity is compared. Declare the intended layer order first. Normal declarations outside any layer outrank normal declarations in layers.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Order groups of rules with @layer</title>
  <style>
    @layer base, theme;
    @layer base { .notice { color: teal; } }
    @layer theme { p { color: purple; } }
  </style>
</head>
<body>
<p class="notice">Your order is ready.</p>
<p>Your package is on the way.</p>
</body>
</html>

What to expect Both paragraphs are purple because the theme layer comes later.

Official references