Skip to content

no-invalid-position-declaration

Reports a declaration at the top of a file, or in an at-rule such as @media that is not inside a rule.

CSS has declarations only inside a rule. At the top of a file the declaration is a syntax error and the browser skips it and the text up to the next } or ;, which may take the next rule with it.

To fix, put the declaration in a rule.

Reported
...
}
@media (a) { top: 0; }
@media (b) { top: 0; }
...
--b: 2;
...
css:
lint:
rules:
no-invalid-position-declaration: warn # off, warn (default), error
less:
lint:
rules:
no-invalid-position-declaration: warn # off, warn (default), error
scss:
lint:
rules:
no-invalid-position-declaration: warn # off, warn (default), error

Enabled by the presets: css/stylelint-recommended.

Suppress one line with sudsy-disable-next-line no-invalid-position-declaration in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
stylelint no-invalid-position-declaration full