Skip to content

useLayeredStyles (CSS)

Language CSS
biome.json
{
"linter": {
"rules": {
"nursery": {
"useLayeredStyles": "error"
}
}
}
}

Enforce style rules to be defined within a cascade layer.

This rule reports style rules that are not contained within a cascade layer (@layer). Rules outside of a cascade layer (excluding !important) always take precedence over layered rules, making the cascade more difficult to predict and override.

.my-style {
color: red;
}
code-block.css:1:1 lint/nursery/useLayeredStyles ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This style rule is defined outside of a cascade layer.

> 1 │ .my-style {
^^^^^^^^^^^
> 2 │ color: red;
> 3 │ }
^
4 │

Style rules outside a cascade layer always take precedence over layered styles, which makes the cascade harder to predict and override.

Wrap the style rule in a @layer block to control its place in the cascade.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

@media (min-width: 600px) {
.my-style {
color: red;
}
}
code-block.css:2:3 lint/nursery/useLayeredStyles ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This style rule is defined outside of a cascade layer.

1 │ @media (min-width: 600px) {
> 2 │ .my-style {
^^^^^^^^^^^
> 3 │ color: red;
> 4 │ }
^
5 │ }
6 │

Style rules outside a cascade layer always take precedence over layered styles, which makes the cascade harder to predict and override.

Wrap the style rule in a @layer block to control its place in the cascade.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

@import "foo.css";
code-block.css:1:2 lint/nursery/useLayeredStyles ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This import is defined outside of a cascade layer.

> 1 │ @import "foo.css";
^^^^^^^^^^^^^^^^^
2 │

Imported styles without a cascade layer always take precedence over layered styles, which makes the cascade harder to predict and override.

Add the layer keyword after the import to control its place in the cascade.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

@layer {
.my-style {
color: red;
}
}
@layer base {
.my-style {
color: red;
}
}
@layer base {
@media (min-width: 600px) {
.my-style {
color: red;
}
}
}
@import "foo.css" layer;
@import "foo.css" layer(base);

Whether @import rules must specify a cascade layer.

When set to false, @import rules without a layer keyword are allowed.

Default: true

biome.json
{
"linter": {
"rules": {
"nursery": {
"useLayeredStyles": {
"level": "on",
"options": {
"requireImportLayers": false
}
}
}
}
}
}
@import "foo.css";