<rule-list> CSS typeThe <rule-list> CSS data type represents a sequence of zero or more CSS rules. It is used to define places in CSS where multiple rules may appear, such as the top level of a stylesheet or inside grouping at-rules like @media or @supports.
A <rule-list> is not written directly. Instead, it describes how the CSS parser collects and interprets rules inside a block or stylesheet.
A <rule-list> is defined as a sequence of zero or more:
p { color: red; }).@media (width < 600px) { ... }).All whitespace, comments, and invalid or malformed constructs are handled according to the CSS parser rules.
The <rule-list> type appears in the specification anywhere CSS is defined to contain a "list of rules."
Examples include:
@media, @custom-media, @supports, @layer, @container.Although authors cannot explicitly write <rule-list>, understanding it is crucial when interpreting how CSS parses nested structures, how invalid rules are dropped, and how the cascade forms within conditional blocks.
<rule-list> in a stylesheetThe following stylesheet is treated as a <rule-list> containing two style rules and an at-rule.
p {
margin: 0;
}
h1 {
font-size: 2rem;
}
@media (width < 600px) {
body {
background: lightgray;
}
}<rule-list> inside @media at-ruleThe block contained inside an @media at-rule is a <rule-list> containing one or more style rules. The following example contains two style rules.
@media (prefers-color-scheme: dark) {
main {
background: black;
color: white;
}
a {
color: skyblue;
}
}<rule-list>The invalid token sequence (!invalid-rule) is ignored by the parser. The rest of the rules form a valid <rule-list>.
body {
color: black;
}
!invalid-rule
@supports (display: grid) {
section {
display: grid;
}
}@supports at-rule@media at-rule@custom-media at-rule