noMissingVarFunction (CSS)
Language CSS
Summary
Section titled “Summary”- Rule available since:
v1.9.2 - Diagnostic Category:
lint/correctness/noMissingVarFunction - This rule is recommended, meaning it is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "correctness": { "noMissingVarFunction": "error" } } }}Description
Section titled “Description”Require var() when using a declared CSS custom property.
Custom property names begin with --, but their values must be read with var(--name).
Writing the name directly does not substitute the custom property’s value.
The rule has the following limits:
- It reports only custom properties that are declared and visible in the same source.
- It skips properties where a name beginning with
--can be an ordinary value. - It skips the following properties:
animationanimation-namecontainer-namecounter-incrementcounter-resetcounter-setgrid-columngrid-column-endgrid-column-startgrid-rowgrid-row-endgrid-row-startlist-stylelist-style-typetransitiontransition-propertyview-transition-namewill-change
Examples
Section titled “Examples”Invalid
Section titled “Invalid”a { --foo: red; color: --foo;}code-block.css:3:10 lint/correctness/noMissingVarFunction ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ CSS variables '--foo' is used without the 'var()' function
1 │ a {
2 │ --foo: red;
> 3 │ color: --foo;
│ ^^^^^
4 │ }
5 │
ℹ CSS variables should be used with the 'var()' function to ensure proper fallback behavior and browser compatibility.
.parent { --foo: red; .child { color: --foo; }}code-block.css:4:12 lint/correctness/noMissingVarFunction ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ CSS variables '--foo' is used without the 'var()' function
2 │ --foo: red;
3 │ .child {
> 4 │ color: --foo;
│ ^^^^^
5 │ }
6 │ }
ℹ CSS variables should be used with the 'var()' function to ensure proper fallback behavior and browser compatibility.
@property --bar {}
a { color: --bar;}code-block.css:4:10 lint/correctness/noMissingVarFunction ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ CSS variables '--bar' is used without the 'var()' function
3 │ a {
> 4 │ color: --bar;
│ ^^^^^
5 │ }
6 │
ℹ CSS variables should be used with the 'var()' function to ensure proper fallback behavior and browser compatibility.
:root { --baz: 0;}
a { --foo: --baz;}code-block.css:6:10 lint/correctness/noMissingVarFunction ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ CSS variables '--baz' is used without the 'var()' function
5 │ a {
> 6 │ --foo: --baz;
│ ^^^^^
7 │ }
8 │
ℹ CSS variables should be used with the 'var()' function to ensure proper fallback behavior and browser compatibility.
p { color: var(--foo);}p { --foo: red; color: var(--foo);}An undeclared name is not reported because the rule cannot determine whether it was meant to refer to a custom property:
p { color: --foo;}*:root {--global: red;}
a { color: var(--global);}@property --global-value {}a { color: var(--global-value);}a { view-transition-name: --bbb;}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.