Skip to content

noDuplicateSelectors (CSS)

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

Disallow duplicate selectors.

Two rules are duplicates when their selectors target the same elements within the same surrounding at-rules. The comparison treats equivalent spellings as equal:

  • whitespace differences are ignored;
  • HTML element names are compared without case (DIV equals div);
  • the order of combined parts is ignored (.a.b equals .b.a);
  • the order of a selector list is ignored (.a, .b equals .b, .a).

Nested selectors are expanded before comparison. For example, a { & b {} } is compared as a b. A selector inside an at-rule such as @media is compared only with selectors inside the same at-rule, not with a matching selector at the top level.

.foo {}
.foo {}
code-block.css:2:1 lint/nursery/noDuplicateSelectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Duplicate selector list ".foo".

1 │ .foo {}
> 2 │ .foo {}
│ ^^^^^^^
3 │

ℹ It was first defined here.

> 1 │ .foo {}
│ ^^^^^^^
2 │ .foo {}
3 │

ℹ Remove or merge the duplicate rule to keep the stylesheet clean.

ℹ 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.

.foo, .bar {}
.bar, .foo {}
code-block.css:2:1 lint/nursery/noDuplicateSelectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Duplicate selector list ".bar, .foo".

1 │ .foo, .bar {}
> 2 │ .bar, .foo {}
│ ^^^^^^^^^^^^^
3 │

ℹ It was first defined here.

> 1 │ .foo, .bar {}
│ ^^^^^^^^^^^^^
2 │ .bar, .foo {}
3 │

ℹ Remove or merge the duplicate rule to keep the stylesheet clean.

ℹ 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.

a b {}
a {
& b {}
}
code-block.css:3:3 lint/nursery/noDuplicateSelectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Duplicate selector list "a b".

1 │ a b {}
2 │ a {
> 3 │ & b {}
│ ^^^^^^
4 │ }
5 │

ℹ It was first defined here.

> 1 │ a b {}
│ ^^^^^^
2 │ a {
3 │ & b {}

ℹ Remove or merge the duplicate rule to keep the stylesheet clean.

ℹ 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.

.foo {}
.bar {}
.foo {}
@media (min-width: 600px) {
.foo {}
}
.foo {
.foo {}
}