At-rules extend CSS beyond normal selectors. They declare encoding, import other files, register custom fonts, and define animation keyframes. This hub explains what at-rules are, when to use each one, and links to full tutorials with four try-it examples each.
01
@charset
Encoding.
02
@import
Modular CSS.
03
@font-face
Web fonts.
04
@keyframes
Animation.
05
Placement
Top of file.
06
4 guides
Full index.
Fundamentals
Introduction
In CSS, at-rules are special statements that begin with @ and control how stylesheets behave. Unlike regular rules that target HTML elements with selectors, at-rules handle encoding, file imports, custom fonts, animations, and more.
What Are CSS At-Rules?
An at-rule provides meta-instructions to the browser about your stylesheet. Some end with a semicolon (@import, @charset); others use a block with curly braces (@font-face, @keyframes).
At-rules enable modular CSS, custom typography, and motion effects that would be impossible with selectors alone. Understanding placement rules — especially for @charset and @import — prevents subtle parsing bugs.
💡
Beginner Tip
Start with @font-face if you want custom fonts, or @keyframes if you want animations. Save @charset and @import for when you split CSS into multiple files.
At-rule — @import url("theme.css"); — starts with @, special syntax.
Related — @media is also an at-rule (covered in the Media Queries section).
Foundation
📝 Syntax
Common at-rules side by side:
CSS
/* Must be first (if used) */@charset"UTF-8";/* Before other rules */@importurl("variables.css");/* Custom font registration */@font-face{font-family:MyFont;src:url("myfont.woff2")format("woff2");}/* Named animation steps */@keyframesfadeIn{from{opacity:0;}to{opacity:1;}}
Placement rules
@charset — first in file; only one allowed
@import — after @charset, before all other rules
@font-face / @keyframes — anywhere, often grouped at top
Common at-rules on this site:
@charset@import@font-face@keyframes
Cheat Sheet
⚡ Quick Reference
At-rule
Purpose
Syntax style
@charset
Declare file encoding (UTF-8)
Semicolon
@import
Include another stylesheet
Semicolon
@font-face
Register a custom font
Block { }
@keyframes
Define animation steps
Block { }
@media
Responsive conditional styles
Block { } (see Media Queries)
Context
When to Use Each At-Rule
@charset — External CSS files with non-ASCII characters when encoding might be ambiguous.
@import — Splitting a project into theme, reset, and component files inside one entry stylesheet.
@font-face — Loading brand fonts not available on user systems.
The animation property runs the fadeIn keyframes over 2 seconds with easing.
Tips
💬 Usage Tips
Order matters — Put @charset and @import at the very top.
Prefer link for critical CSS — Use <link> in HTML for faster parallel downloads.
woff2 first — In @font-face, list modern formats before fallbacks.
Name keyframes clearly — Use descriptive names like slideUpMenu not anim1.
Group at-rules — Keep fonts and keyframes in dedicated partial files.
Watch Out
⚠️ Common Pitfalls
@import after rules — Browsers ignore @import not at the top.
Comments before @charset — Strict parsers may reject anything before @charset.
Chained @import — Nested imports slow loading; prefer flat structure or HTML links.
Missing font formats — Provide woff2; add fallbacks for older browsers if needed.
Animation without keyframes — animation: fadeIn fails if @keyframes fadeIn is missing.
🧠 How CSS At-Rules Work
1
Parser sees @
The CSS engine recognizes an at-rule instead of a selector.
Parse
2
Rule-specific action
Import files, register fonts, or store keyframe definitions.
Process
3
Cascade with normal rules
Imported and declared styles merge with selector rules by cascade order.
Apply
=
@
Enhanced stylesheet
Modular files, custom fonts, and animations work together on the page.
Compatibility
🖥 Browser Compatibility
The at-rules covered on this page — @charset, @import, @font-face, and @keyframes — have 100% browser support in Chrome, Firefox, Safari, Edge, and Opera.
✓ Baseline · Universal support
CSS At-Rules
All major browsers support these at-rules in linked .css files and embedded <style> blocks.
100%Modern browsers
Google ChromeAll versions · External CSS
Full support
Mozilla FirefoxAll versions · External CSS
Full support
Apple SafariAll versions · External CSS
Full support
Microsoft EdgeAll versions · External CSS
Full support
OperaAll modern versions
Full support
CSS at-rules100% supported
Bottom line:@charset, @import, @font-face, and @keyframes are safe for production. Prefer <link> over @import for critical-path performance; use woff2 in @font-face for best font loading.
Wrap Up
🎉 Conclusion
CSS at-rules control stylesheet behavior beyond normal selectors. They enable modular CSS with @import, correct encoding with @charset, custom typography with @font-face, and rich motion with @keyframes.
Use this hub to compare at-rules, then dive into each tutorial for try-it examples and detailed FAQs. Pair at-rules with media queries and properties for complete responsive designs.
Your map to all four at-rule tutorials on this site.
5
Core concepts
@01
At-rule
Starts with @.
Syntax
utf02
@charset
First line.
Encode
imp03
@import
Modular.
Files
font04
@font-face
Custom.
Type
key05
@keyframes
Motion.
Animate
❓ Frequently Asked Questions
An at-rule is a CSS statement that starts with @ and provides instructions beyond normal selector blocks. Examples include @charset for encoding, @import for other files, @font-face for custom fonts, and @keyframes for animations.
Regular rules use selectors like p or .card followed by { property: value; }. At-rules begin with @ and often have special syntax — some use a block { }, others end with a semicolon like @import url("file.css");
@charset must be the very first item if used. @import rules must come before any other rules except @charset. @font-face and @keyframes can appear anywhere, though many developers group them near the top.
@keyframes defines named animation steps. You reference that name with animation: fadeIn 2s; on an element. Pair @keyframes with transition or animation properties for motion effects.
For performance, <link rel="stylesheet"> in HTML is usually better because browsers download linked files in parallel. @import is convenient for splitting CSS into modules inside one file, but it can slow page load.
Read the overview and comparison table, try the five examples, then open the @charset tutorial first if you are new to at-rules. Follow the sidebar order: charset, font-face, import, keyframes.