Sass At-Rules

What You’ll Learn
At-rules start with @ and tell Sass what to do. Some load code (@use), some define reusable pieces (@mixin, @function), some control flow (@if, @each), and plain CSS at-rules like @media pass through with extra Sass features.
@use "sass:math";
@mixin card($pad: 1rem) {
padding: $pad;
}
.box {
@include card(2rem);
@if math.div(1, 2) == 0.5 {
border-width: 1px;
}
@media (min-width: 768px) {
padding: 3rem;
}
} At-Rule Index
Modules & Loading
Load other stylesheets and re-export them.
@useTutorialLoad a module with a namespace.
@forwardTutorialRe-export a module’s members.
@import (deprecated)TutorialThe legacy global import rule.
Reusable Code
Share styles, logic, and selectors.
@mixin / @includeTutorialDefine and include reusable style blocks.
@functionTutorialReturn computed values.
@extendTutorialShare styles between selectors.
Messages
Report problems and inspect values.
@errorTutorialStop compilation with a message.
@warnTutorialPrint a warning and keep going.
@debugTutorialPrint a value while developing.
Selectors & CSS
Escape nesting and use plain CSS at-rules.
@at-rootTutorialEmit rules at the document root.
CSS at-rulesTutorial@media, @supports, @keyframes and more in Sass.
Flow Control
Branch and loop at compile time.
Frequently Asked Questions
Next: Sass @use Rule
Start with the first tutorial in this section.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful
