Sass @debug Rule

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
Inspect · keep compiling

What You’ll Learn

Sass @debug prints the value of a variable or expression while you develop—along with the filename and line number. This page covers syntax, inspecting any Sass type, how @debug differs from @warn and @error, and five compiled examples.

01

Print

@debug

02

Locate

File + line

03

Any value

Not just strings

04

Continue

CSS still ships

05

Vs warn

Inspect vs tip

06

Practice

5 examples

What Is @debug?

Official docs: sometimes it is useful to see the value of a variable or expression while you are developing your stylesheet. That is what the @debug rule is for: written @debug <expression>, it prints the value of that expression, along with the filename and line number.

  • Messages appear in the compiler / terminal / build log—not in the CSS file.
  • Compilation continues; CSS is still produced.
  • You can pass any Sass value, not just a string.
  • Printed representation matches meta.inspect().
  • Exact message format varies by Sass implementation.
💡
Beginner tip

Think of @debug as console.log for Sass. Use it while you figure out math, maps, and mixin arguments—then remove it before you ship.

📝 Syntax

styles.scss
@mixin inset-divider-offset($offset, $padding) {
  $divider-offset: (2 * $padding) + $offset;
  @debug "divider offset: #{$divider-offset}";

  margin-left: $divider-offset;
  width: calc(100% - #{$divider-offset});
}

Label the printed value with a short string so logs stay readable when you have several @debug lines.

📤 Debug Messages

Official docs: the exact format varies by implementation. In Dart Sass it often looks like:

styles.scss
test.scss:3 Debug: divider offset: 132px
💡
Any value works

Official fun fact: pass numbers, colors, maps, lists, null, booleans—Sass prints them the same way meta.inspect() would.

⚖️ @debug vs @warn vs @error

At-ruleStops compile?Best for
@debugNoInspecting values while developing
@warnNoDeprecations and soft tips for API users
@errorYesInvalid usage that must not continue

Use @debug for yourself while building. Use @warn / @error when talking to other developers through your library API.

🛡️ Common @debug Patterns

  • Intermediate math — print a computed length before it hits CSS.
  • Maps & lists — inspect tokens and list.nth results.
  • Inside functions — log inputs and the returned value.
  • Loops — print each breakpoint or theme key as you iterate.
  • Type checks@debug meta.type-of($x) when values look wrong.

⚡ Quick Reference

GoalCode
Print a label + value@debug "offset: #{$x}";
Print any value@debug $theme;
Inspect like meta@debug meta.inspect($map);
Check a type@debug meta.type-of($value);
Soft tip to usersUse @warn
Hard failUse @error

Examples Gallery

Each example still produces CSS. Open View Compiled CSS and View Debug Output to see both sides of @debug.

📚 Getting Started

Print intermediate values while styles still compile.

Example 1 — Debug a Computed Length

Official-style mixin: inspect an offset before it becomes CSS.

styles.scss
@mixin inset-divider-offset($offset, $padding) {
  $divider-offset: (2 * $padding) + $offset;
  @debug "divider offset: #{$divider-offset}";

  margin-left: $divider-offset;
  width: calc(100% - #{$divider-offset});
}

.panel {
  @include inset-divider-offset(12px, 60px);
}

How It Works

(2 * 60px) + 12px equals 132px. @debug prints that result so you can confirm the math without guessing from the final CSS alone.

Example 2 — Maps, Lists & Types

Pass non-string values directly to @debug.

styles.scss
@use "sass:map";
@use "sass:list";
@use "sass:meta";

$theme: (
  primary: #036,
  radius: 8px,
);

@debug $theme;
@debug map.get($theme, primary);
@debug list.nth(10px 20px 30px, 2);
@debug meta.type-of(#036);

.box {
  color: map.get($theme, primary);
  border-radius: map.get($theme, radius);
  padding: list.nth(10px 20px 30px, 2);
}

How It Works

Maps print in parentheses, colors and lengths print as Sass values, and meta.type-of reports color for #036.

📈 Functions, Loops & Mixed Types

Trace helpers and iteration while CSS still ships.

Example 3 — Debug Inside a Function

Log each call’s inputs and result from a rem() helper.

styles.scss
@use "sass:math";

@function rem($px, $base: 16px) {
  $result: math.div($px, $base) * 1rem;
  @debug "rem(#{$px}, #{$base}) => #{$result}";
  @return $result;
}

.title {
  font-size: rem(24px);
  padding: rem(8px, 16px);
}

How It Works

Each call prints once. Handy when a helper is used in many places and you need to see every conversion.

Example 4 — Debug Inside a Loop

Print every breakpoint name and width while generating media queries.

styles.scss
$breakpoints: (
  sm: 480px,
  md: 768px,
  lg: 1024px,
);

@each $name, $width in $breakpoints {
  @debug "breakpoint #{$name} = #{$width}";

  @media (min-width: $width) {
    .container-#{$name} {
      max-width: $width;
    }
  }
}

How It Works

The loop emits one debug line per map entry, then the matching @media rule.

Example 5 — Colors, Maps, Null & Strings

See how different Sass types look in the debug log.

styles.scss
@use "sass:color";
@use "sass:meta";

$brand: #036;

@debug $brand;
@debug color.scale($brand, $lightness: 40%);
@debug meta.inspect((ok: true, count: 3));
@debug null;
@debug "plain string";

.swatch {
  background: $brand;
  color: color.scale($brand, $lightness: 40%);
}

How It Works

Colors, maps, null, and strings each print clearly—same idea as meta.inspect().

🚀 Real-World Use Cases

  • Spacing math — confirm offsets before calc().
  • Design tokens — inspect maps while building a theme.
  • Helper functions — trace rem(), clamp, or color scales.
  • Generated CSS — verify loop keys and media widths.
  • Type confusion — print meta.type-of when a value misbehaves.

🧠 How Compilation Works

1

Hit @debug

Sass evaluates the expression at that point in the stylesheet.

Source
2

Print to the log

Filename, line, and the inspected value appear in the terminal.

Log
3

Keep compiling

Unlike @error, the build does not stop.

Continue
4

CSS ships

Styles emit; debug lines stay out of the CSS file.

⚠️ Common Pitfalls

  • Leaving @debug in production — noisy logs; remove when done.
  • Using @debug as an API warning — prefer @warn for callers.
  • Expecting CSS output — debug never appears in the stylesheet.
  • Spam in loops — large maps can flood the terminal.
  • Confusing with @error@debug never fails the build.

💡 Best Practices

✅ Do

  • Label values: @debug "offset: #{$x}"
  • Debug intermediate calculations before CSS
  • Inspect maps/lists with direct @debug $map
  • Remove debug statements before merging
  • Use meta.type-of when types look wrong

❌ Don’t

  • Ship permanent @debug in shared libraries
  • Replace @warn / @error with debug prints
  • Assume every build tool shows debug the same way
  • Debug huge structures on every rebuild forever
  • Expect browsers to see @debug

Key Takeaways

Knowledge Unlocked

Five things to remember about Sass @debug

Inspect any value with file + line—compilation keeps going.

5
Core concepts
📄 02

Locate

file + line

Log
📦 03

Any type

like meta.inspect

Values
🔀 04

Continue

CSS still emits

Build
05

Temporary

remove before ship

Dev

❓ Frequently Asked Questions

It prints the value of an expression along with the filename and line number so you can inspect variables and calculations while developing your stylesheet.
No. Like @warn, it continues compiling and still emits CSS. Only @error stops the build.
Yes. Official docs: you can pass any value. Sass prints the same representation as meta.inspect().
In the compiler / terminal / build log—not in the CSS file. Exact formatting varies by Sass implementation.
@debug is for inspecting values during development. @warn is for soft guidance to API users (deprecations, tips) and usually includes a stack trace meant for callers.
No. Remove or comment out debug statements before shipping so build logs stay clean. Prefer temporary checks while developing.
Did you know?

Official Sass docs note that @debug prints the same representation of a value as meta.inspect()—so maps, lists, and colors stay readable in the log.

Conclusion

@debug is your Sass console: print any value with a file and line, keep compiling, then remove the noise when you are done. Use @warn and @error when talking to API consumers instead.

Continue with @at-root or @warn.

Next: Sass @at-root

Escape nesting and control @media / @supports wrappers with with/without queries.

@at-root rule →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful