Firefox 161, released on 24 November 2026, quietly shipped a CSS change that makes custom properties and attr() much more flexible: the var(), attr() and env() functions now accept nested functions in their first parameter. In plain terms, the name of the variable you read can itself come from another variable or from an HTML attribute.

The Firefox 161 release notes for developers give two examples: var(attr(data-theme-prop type())) and env(var(--safe-area-block-start)). This tutorial explains what that means, shows practical patterns, and covers how to ship it safely, because at the time of writing it is not supported everywhere. We tested every example in Firefox 161.0 and in Chrome 156 on Linux.

The idea: computed variable names

Normally, the argument to var() is a fixed name you type in your stylesheet:

.card { color: var(--brand); }

With nested substitution, the name can be computed:

/* The variable name comes from an HTML attribute */
.card { color: var(attr(data-color-var type(<custom-ident>))); }

/* The variable name comes from another variable */
.panel { --which: --accent; color: var(var(--which)); }

The inner function is resolved first, producing a name like --brand, and then the outer var() looks that name up.

Pattern 1: choose a design token from HTML

Say your design system defines colour tokens on :root:

:root {
  --brand: rgb(200, 0, 0);
  --accent: rgb(0, 0, 200);
  --success: rgb(0, 128, 0);
}

.badge {
  background: var(attr(data-tone type(<custom-ident>)), gray);
  color: white;
  padding: 0.25em 0.6em;
  border-radius: 999px;
}
<span class="badge" data-tone="--brand">New</span>
<span class="badge" data-tone="--accent">Beta</span>
<span class="badge" data-tone="--success">Stable</span>

Each badge picks its token from the data-tone attribute, and you never write a .badge--brand modifier class. In our Firefox 161 test, a block using var(attr(data-color-var type(<custom-ident>))) with data-color-var="--brand" rendered in rgb(200, 0, 0), exactly the value of --brand.

Why type(<custom-ident>) matters

Modern attr() returns a string unless you tell it the type. A string like "--brand" is not a valid variable name, so the lookup would fail. type(<custom-ident>) tells the browser to parse the attribute as an identifier, which is what var() expects. The Firefox release note shows a bare type() in its shorthand example; in our own code we spelled out type(<custom-ident>) and it worked.

Fallbacks still work

If the attribute is missing, the inner attr() can’t produce a name, and the outer var() falls back:

.badge { background: var(attr(data-tone type(<custom-ident>)), rgb(0, 128, 0)); }

We confirmed this in Firefox 161: an element without the attribute got the green fallback.

Pattern 2: indirection with var(var())

Indirection lets a component choose which token to use while the theme decides what the token is:

:root {
  --surface-light: #ffffff;
  --surface-dark: #1e1e1e;
}

.card          { --surface-token: --surface-light; }
.card.is-inverted { --surface-token: --surface-dark; }

.card { background: var(var(--surface-token)); }

In our test, --which: --accent; background: var(var(--which)); rendered rgb(0, 0, 200) in Firefox 161, the value of --accent.

This is not a replacement for normal theming with custom properties. It is most useful when the choice is data-driven, for example a CMS field that stores a token name.

Pattern 3: env() with a computed name

env() reads environment values such as the safe-area insets on phones with notches. Nested substitution lets you choose which inset to read through a variable, and the fallback still applies if the name is unknown:

.toolbar {
  --edge: safe-area-inset-top;
  padding-top: calc(env(var(--edge), 0px) + 8px);
}

.toolbar.at-bottom {
  --edge: safe-area-inset-bottom;
  padding-top: 8px;
  padding-bottom: calc(env(var(--edge), 0px) + 8px);
}

On desktop Firefox 161 we checked the mechanics: with --inset: safe-area-inset-top, calc(env(var(--inset), 40px) + 10px) produced a 10px-tall box (the inset is 0 on desktop), and with an unknown name env(var(--inset), 40px) produced the 40px fallback.

Browser support and feature detection

This is the important part. In our tests, Chrome 156 did not support nested functions in the first parameter of var(). Every nested example rendered as if the declaration were invalid. Firefox 161 supported all of them. We did not test Safari, so check MDN’s var() compatibility data before relying on it.

Because unsupported browsers treat the whole declaration as invalid at computed-value time, always provide a normal declaration first and wrap the nested version in @supports:

.badge { background: gray; } /* safe default everywhere */

@supports (color: var(var(--x))) {
  .badge { background: var(attr(data-tone type(<custom-ident>)), gray); }
}

We tested this exact @supports (color: var(var(--x))) check: it matched in Firefox 161 and did not match in Chrome 156, so the fallback rule applied there.

A note on invalid-at-computed-value-time

If you skip @supports and a browser can’t resolve the nested var(), the property becomes “invalid at computed-value time”. That doesn’t fall back to your previous declaration in the same rule; it falls back to the inherited or initial value. That is why the nested examples in our Chrome test rendered with transparent backgrounds, and why @supports is the safer pattern.

When to use it, and when not to

Good uses:

  • Data-driven styling where a CMS or API stores a token name.
  • Component libraries that want one class with many token-based variants.
  • Choosing between related environment values with a single variable.

Think twice when:

  • A plain modifier class would be clearer for your team.
  • The attribute value comes from users. Only token names you define will resolve, but you still don’t want arbitrary input deciding your styling, so validate values server-side.
  • You need consistent behaviour in every browser today. Until other engines ship it, treat it as progressive enhancement.

Other CSS in Firefox 161

The same release also shipped the random() CSS function and the CSS Typed Object Model, which completes Typed OM support across the major engines (colour value interfaces aren’t supported in any browser yet). Firefox 161 also added Compression Dictionary Transport on the HTTP side, which can shrink repeat downloads of large JavaScript bundles.

Takeaway

Firefox 161 lets var(), attr() and env() compute the name they read, enabling patterns like var(attr(data-tone type(<custom-ident>))) and var(var(--token)). It is a neat tool for data-driven design tokens, but in our testing Chrome 156 didn’t support it, so ship it behind @supports (color: var(var(--x))) with a plain fallback. Bookmark the Firefox 161 developer notes and check MDN’s compatibility tables as other browsers catch up.