Directive
Example
.nav {
display: flex;
}
@import url("theme.css");@import url("theme.css");
.nav {
display: flex;
}@import only works before all other rules except @charset and @layer statements.
Common mistakes
- An
@importplaced after other rules is ignored. - Writing
@media (max-width: 600)without a unit, so it never matches.
Key points
@charsetand@importsit at the top of the stylesheet, before other rules.- Media queries use
@mediawith valid conditions, like(width >= 48rem). - Feature checks use
@supportsinstead of browser sniffing in JS.
Interview questions
What is the difference between an at-rule and a selector rule?
A selector rule styles elements. An at-rule starts with @ and gives instructions, such as conditions, imports, fonts or animations.
Can at-rules be nested?
Yes, conditional at-rules like @media, @supports and @container can be nested inside each other and inside style rules.