useLayeredStyles (CSS)
Language CSS
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useLayeredStyles - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Inspired from
css/use-layers
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useLayeredStyles": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”.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);Options
Section titled “Options”requireImportLayers
Section titled “requireImportLayers”Whether @import rules must specify a cascade layer.
When set to false, @import rules without a layer keyword are allowed.
Default: true
{ "linter": { "rules": { "nursery": { "useLayeredStyles": { "level": "on", "options": { "requireImportLayers": false } } } } }}@import "foo.css";Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.