When writing mixins and functions, you may want to discourage certain arguments — legacy values, typos you still handle, or suboptimal API use. The Sass @warn rule is built for that. Write @warn <expression>; (usually a string). Sass prints the value plus a stack trace, but does not stop compilation.
Unlike @error, CSS can still be emitted after a warning. Use @debug for temporary value inspection while developing.
Official intent.
Per the Sass docs: guide callers away from deprecated or suboptimal usage without breaking their build.
Not in the CSS file.
Warnings go to the terminal / build log. Browsers never see @warn.
Soft, not fatal.
If continuing would produce broken CSS, use @error instead of @warn.
Warning: Unknown theme color `neon`. Falling back to primary.
theme.scss 10:5 theme-color()
theme.scss 22:3 root stylesheet
How It Works
accent resolves to #c45.
neon is missing, so Sass warns.
Fallback to primary keeps a color on the page.
Build succeeds while the token name gets fixed.
Example 5 — Deprecated Function Alias
Keep an old name working while steering callers to the new one.
SCSS
@function fg($args...) {
@warn "The fg() function is deprecated. Call foreground() instead.";
@return foreground($args...);
}
@function foreground($color) {
@return $color;
}
.title {
color: fg(#222);
}
Compiled CSS
.title {
color: #222;
}
Compiler warning (CSS still produced)
Warning: The fg() function is deprecated. Call foreground() instead.
alias.scss 2:3 fg()
alias.scss 11:10 root stylesheet
How It Works
Old name fg() still works.
$args... forwards every argument.
Warning pushes migration to foreground().
CSS result is unchanged during the rename period.
Edge Cases & Pitfalls
Most @warn mistakes are wrong severity, vague messages, or warning noise.
severity
Do not soft-warn fatal bugs
If CSS would be wrong or unsafe, use @error. Soft warnings hide breakages in CI.
message
Say what to do next
Include the bad value and the preferred alternative: "Use lg instead."
noise
Avoid warning on every call forever
Deprecation windows should end. Remove the alias once callers migrate.
debug
Not a debugger
Temporary value dumps belong in @debug, not long-lived @warn calls.
Toolchain
Sass Support
@warn is a core Sass messaging at-rule. Warning format varies slightly by implementation and build tool; continuing the compile is consistent.
Implementation
Status
Dart Sass
Supported (recommended)
LibSass / node-sass
Supported (deprecated toolchain)
Ruby Sass
Supported (end-of-life)
Browsers
N/A — warnings stay in the build log
Prefer Dart Sass for new projects. SCSS and indented syntax both support @warn.
Remember
Key Takeaways
Soft signal:@warn prints a message + stack and keeps compiling.
Guide callers on deprecations, typos, and suboptimal API use.
Still emit CSS (or remap) after the warning.
Fatal mistakes? Use @error. Inspecting? Use @debug.
One line:@warn is your yellow light for Sass APIs — clear guidance without stopping the build.
Compile
Compile Notes
@warn never reaches the browser. Conceptual flow:
flow.txt
1. Call a mixin / function with arguments
2. Hit a soft check (@if + recoverable case)
3. @warn prints message + stack to the build log
4. Continue: remap, fall back, or emit as-is
5. CSS still compiles for the stylesheet
Frequently Asked Questions
It prints the value of an expression (usually a string) plus a stack trace for the user, but unlike @error it does not stop Sass from compiling the stylesheet.
Use it to discourage legacy or suboptimal arguments, flag typos that you still handle, announce deprecations, or guide callers without breaking their build.
@warn continues compilation and still emits CSS. @error aborts the compile. Prefer @error when continuing would produce broken output.
No. Warnings go to the compiler / terminal / build log. The CSS may still include whatever styles your mixin emitted after the warning.
Build tools and Sass CLIs often have quiet or fatal-warning options. Exact flags depend on your Sass version and bundler—check Dart Sass docs for --quiet and related options.
No. Soft warnings are for recoverable cases. If the API cannot continue safely, use @error instead.