CSS At-Rules are special CSS statements that start with:
[code theme="dark"] @ [/code]symbol.
They are used to define special behaviors, conditions, imports, animations, responsive rules, layers, fonts, and many advanced CSS features.
At-rules help developers create:
| At-Rule | Purpose |
|---|---|
| @media | Responsive design |
| @keyframes | CSS animations |
| @import | Import CSS files |
| @font-face | Custom fonts |
| @supports | Feature detection |
| @container | Container queries |
| @layer | CSS layering system |
Used for responsive design.
[code theme="dark"] @media (max-width:768px){ .menu{ display:none; } } [/code]Applies styles only on smaller screens.
Used for CSS animations.
[code theme="dark"] @keyframes fade{ from{ opacity:0; } to{ opacity:1; } } [/code]Imports external CSS files.
[code theme="dark"] @import url("style.css"); [/code]Used to load custom fonts.
[code theme="dark"] @font-face{ font-family:"MyFont"; src:url("font.woff2"); } [/code]Applies styles only if a browser supports a feature.
[code theme="dark"] @supports (display:grid){ .layout{ display:grid; } } [/code]Creates responsive components based on container size.
[code theme="dark"] @container (min-width:500px){ .card{ display:flex; } } [/code]Organizes CSS into layers with controlled priority.
[code theme="dark"] @layer components{ .btn{ padding:12px; } } [/code]| Type | Example |
|---|---|
| Conditional Rules | @media, @supports |
| Resource Rules | @import, @font-face |
| Animation Rules | @keyframes |
| Architecture Rules | @layer, @container |
Most common at-rules are supported across all modern browsers.
Older browsers may not support newer at-rules like:
[code theme="dark"] @container @layer [/code]CSS at-rules are one of the most important parts of modern frontend development and advanced CSS architecture.