Dart Sass CLI

Beginner
⏱️ 18 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass command

What You’ll Learn

The Dart Sass command-line interface compiles Sass from your terminal. This page covers one-to-one and many-to-many modes, key flags (--style, --watch, source maps, stdin), and five beginner examples. Install first via Sass Installation.

01

One-to-one

in out

02

Many-to-many

in:out

03

--style

expanded / compressed

04

--watch

Live rebuild

05

Maps & stdin

Dev extras

06

Practice

5 examples

What Is the Dart Sass CLI?

After you install Dart Sass, you get a sass executable. It reads .scss / .sass (and sometimes .css), parses the stylesheet, and writes CSS—either to a file or to the terminal.

  • Extension picks the syntax: .scss → SCSS, .sass → indented, .css → plain CSS.
  • Unknown extensions or stdin default to SCSS (override with --indented).
  • Partials named _file.scss are skipped when compiling whole directories.
  • Use sass --help and sass --version anytime.
💡
Beginner tip

Start with sass styles.scss styles.css. When that works, add --watch for day-to-day editing and --style=compressed for production builds.

📄 One-to-One Mode

terminal
sass <input.scss> [output.css]

Compiles a single input to a single output. Omit the output path to print CSS to the terminal. Pass - as the input to read from standard input (defaults to SCSS unless --indented is set).

📦 Many-to-Many Mode

Official docs (Dart Sass 1.4.0+): separate inputs from outputs with a colon. You can list several pairs or map a whole directory.

terminal
# One file pair
sass style.scss:style.css

# Several files
sass light.scss:light.css dark.scss:dark.css

# All Sass files in themes/ → public/css/ (skips _partials)
sass themes:public/css

⚙️ Important Options

OptionWhat it does
--style / -sexpanded (default) or compressed
--watch / -wRecompile when sources change (like --update, then keep running)
--updateCompile only out-of-date stylesheets
--stdinRead SCSS/Sass from stdin (not with many-to-many)
--indentedForce indented syntax (handy for stdin)
--load-path / -IExtra folders for @use / imports (repeatable)
--no-source-mapDo not write .css.map files
--quiet / -qHide warnings (and silence @debug)
--interactive / -iREPL for SassScript expressions
--error-cssOn error, emit CSS that shows the message in the browser (on by default when writing files)

Also useful: --poll (with --watch on flaky network drives), --stop-on-error, --verbose, --quiet-deps, --fatal-deprecation, --no-charset, and source-map embedding flags. Run sass --help for the full list on your installed version.

💡
Version note

Some flags need newer Dart Sass (for example --pkg-importer=node since 1.71.0). This site’s examples target common flags available on Dart Sass 1.69+. Upgrade if a flag is missing from sass --help.

🔍 Source Maps

By default, Dart Sass writes source maps next to CSS files so DevTools can show the original SCSS. Disable with --no-source-map. Control link style with --source-map-urls=relative|absolute, or embed with --embed-sources / --embed-source-map.

⚡ Quick Reference

GoalCommand
Compile one filesass styles.scss styles.css
Print CSS onlysass styles.scss
Colon pairsass styles.scss:styles.css
Folder → foldersass scss:css
Watchsass --watch scss:css
Production CSSsass --style=compressed --no-source-map scss:css
From stdinecho "h1{color:red}" | sass --stdin
Interactivesass --interactive

Examples Gallery

Verified with Dart Sass. Open each toggle for CSS or terminal output.

📚 Getting Started

Compile a single file, then a whole folder.

Example 1 — One-to-One Compile (Stdout)

Omit the output path to print CSS in the terminal.

styles.scss
$brand: #036;

h1 {
  font-size: 40px;
  color: $brand;
}
terminal
sass style.scss
# or write a file:
sass style.scss style.css
sass style.scss:style.css

How It Works

Space-separated paths are one-to-one mode. Colon pairs are many-to-many mode for the same single file. Both produce the same CSS.

Example 2 — Compile a Directory (Skip Partials)

Map themes/ to css/. Files starting with _ are not emitted.

terminal
# themes/light.scss, themes/dark.scss, themes/_tokens.scss
sass themes:css

# Result: css/light.css and css/dark.css
# (_tokens.scss is a partial — no css/_tokens.css)

How It Works

Directory mode keeps shared tokens in partials without creating empty CSS files for them.

📈 Style, Stdin & Watch

Production CSS, piping input, and the live-reload loop.

Example 3 — Expanded vs Compressed

Same source; different --style output.

terminal
sass --style=expanded style.scss
sass --style=compressed style.scss

How It Works

Use expanded while learning. Switch to compressed in CI or production npm scripts.

Example 4 — Compile from Stdin

Pipe a snippet into Sass without creating a file.

terminal
echo "h1 {font-size: 40px}" | sass --stdin

# Indented syntax from stdin:
echo -e "h1\n  font-size: 40px" | sass --indented -

How It Works

--stdin (or input -) cannot be combined with many-to-many colon mode. Great for quick experiments.

Example 5 — Watch a Folder

After the first compile, Sass stays open and rebuilds on change.

terminal
sass --watch themes:public/css

# Remote / network drives if OS notifications fail:
sass --watch --poll themes:public/css

# Only rebuild outdated files once:
sass --update themes:public/css

How It Works

Official docs: Sass watches directories you pass on the command line (and load paths)—not every folder discovered only through @use. Stop with Ctrl+C.

🚀 Real-World Use Cases

  • Local learning — one-to-one compile + stdout for instant feedback.
  • Multi-theme sitessass --watch themes:css.
  • CI production--style=compressed --no-source-map.
  • npm scripts — wrap CLI commands in package.json.
  • Quick math checkssass --interactive for SassScript.

🧠 How the CLI Compiles

1

Pick mode

One-to-one paths or many-to-many colon pairs / folders.

Invoke
2

Load & parse

Resolve syntax, load paths, and dependencies.

Read
3

Apply flags

Style, source maps, quiet, update/watch behavior.

Options
4

Emit CSS

Write files (and maps) or print to the terminal.

⚠️ Common Pitfalls

  • Mixing modes — do not combine --stdin with many-to-many pairs.
  • Expecting partial CSS_partial.scss is skipped in directory compiles.
  • Watch not seeing deep folders — only passed dirs / parents / load paths are watched.
  • Surprise source maps — default on; use --no-source-map for clean deploys.
  • Editing generated CSS — the next sass run overwrites it.

💡 Best Practices

✅ Do

  • Put CLI commands in npm scripts for the team
  • Use --watch locally and one-shot compile in CI
  • Prefer directory many-to-many for multi-file themes
  • Keep shared code in _partials
  • Run sass --version in CI to pin/debug toolchains

❌ Don’t

  • Commit compressed CSS as your only source
  • Ignore deprecation warnings forever—use --verbose when cleaning up
  • Assume every flag exists on older Dart Sass
  • Use absolute source-map URLs if CSS will be served elsewhere
  • Forget Ctrl+C to stop a watcher before closing the terminal

Key Takeaways

Knowledge Unlocked

Five things to remember about the Dart Sass CLI

Two modes, clear flags, watch for dev, compress for prod.

5
Core concepts
📦 02

Many-to-many

in:out / dirs

Mode
⚙️ 03

--style

expanded / min

Output
👀 04

--watch

live rebuild

Dev
🔍 05

Source maps

on by default

Debug

❓ Frequently Asked Questions

The sass executable that compiles .scss, .sass, and sometimes .css files to CSS from the terminal. Install it via npm, Homebrew, Chocolatey, or a standalone binary.
sass <input.scss> [output.css] compiles one input file to one output file (or prints CSS to the terminal if you omit the output path).
sass input:output or sass srcDir:outDir compiles one or more pairs. Directory mode writes CSS for each Sass file and skips partials that start with _.
Pass --watch (or -w), usually with colon pairs: sass --watch themes:public/css. Sass recompiles when those files or their dependencies change.
Controls CSS formatting. expanded (default) is readable. compressed removes extra whitespace for production.
Yes when writing CSS files. Pass --no-source-map to skip them. Other flags control relative/absolute URLs and embedding.
Did you know?

Official docs include an interactive mode (sass --interactive) where you can type SassScript like 1px + 1in and see 97px—handy for learning units without creating a stylesheet.

Conclusion

The Dart Sass CLI is your day-to-day compile tool: one-to-one for single files, many-to-many for folders, --watch while editing, and --style=compressed when shipping. Master those, then dive into language features.

Continue with Sass --watch or Sass Variables.

Next: Sass --watch

Keep Sass running and rebuild CSS every time you save.

Sass --watch →

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