TH The Sass Way
Tooling & Workflow

How to Install and Compile Sass (npm, CLI, and Dart Sass)

How to Install and Compile Sass (npm, CLI, and Dart Sass)
tldrInstall Sass with npm by running npm install -D sass in your project, which gives you Dart Sass, the official implementation. Compile a file with npx sass input.scss output.css, or add --watch to recompile on every save. Avoid the deprecated node-sass package. You can also install globally with npm install -g sass, or via Homebrew or Chocolatey.

Install Sass in one line, then compile with one command

The fastest way to install Sass is with npm: run npm install -D sass inside your project, then compile with npx sass input.scss output.css. That gives you Dart Sass, the official and only actively maintained implementation, and it works the same on macOS, Windows, and Linux. Everything else in this guide — the CLI flags, the watch mode, the global install, and the build-tool setups — is just refinement on top of those two commands.

If you only remember two lines, remember these:

npm install -D sass
npx sass scss/main.scss css/main.css

The rest of this guide explains the options so you can pick the install method that fits your project and avoid the outdated versions that still show up in old tutorials.

Which Sass should you install?

There have been three implementations of Sass over the years, and this trips up beginners because search results are full of dead advice. Here is the current state:

Implementation Language Status Should you use it?
Dart Sass Dart Actively maintained, the reference implementation Yes — this is "Sass" today
LibSass (node-sass) C++ Deprecated, no new features No — migrate off it
Ruby Sass Ruby End-of-life since 2019 No

The practical takeaway: install sass, not node-sass. The node-sass package wraps LibSass, which was officially deprecated and no longer receives new Sass features like the modern @use and @forward module system. If you inherit a project using node-sass, plan to swap it for sass — the npm package name is the main thing that changes.

For a refresher on what the preprocessor actually does before you install it, see what is Sass.

If your project already has Node.js and a package.json, npm is the cleanest option. It pins the Sass version per project, so every teammate and your CI server compile with the exact same compiler.

Step 1 — Make sure Node.js is installed

Sass's npm package needs Node. Check whether you have it:

node -v
npm -v

If those print version numbers (Node 14 or newer is fine; any recent LTS is ideal), you're set. If not, install Node.js from nodejs.org first — the LTS build is the safe choice.

Step 2 — Install Sass as a dev dependency

Inside your project folder:

npm install --save-dev sass

The --save-dev flag (shortened to -D) records Sass under devDependencies in package.json, which is correct because Sass is a build tool, not something your shipped site needs at runtime.

Step 3 — Compile a file

Use npx to run the locally installed binary:

npx sass scss/main.scss css/main.css

npx finds the sass executable inside node_modules/.bin so you don't need a global install. The first path is your source, the second is the CSS file Sass writes.

Step 4 — Add npm scripts

Typing that path every time gets old. Add scripts to package.json so the commands are short and self-documenting:

{
  "scripts": {
    "sass": "sass scss/main.scss css/main.css",
    "sass:watch": "sass --watch scss/main.scss css/main.css"
  }
}

Now npm run sass compiles once and npm run sass:watch recompiles automatically on every save.

Method 2: Install Sass globally with the CLI

If you want a sass command available everywhere — handy for quick experiments or projects without a Node setup — install it globally:

npm install -g sass

Then use it directly, no npx:

sass input.scss output.css
sass --watch input.scss output.css

There are also standalone options that don't require Node at all. On macOS you can use Homebrew:

brew install sass/sass/sass

On Windows, Chocolatey works:

choco install sass

The Dart Sass team also publishes standalone archives on the GitHub releases page for people who want a single executable with no package manager. All of these give you the same Dart Sass CLI.

npm vs global install: which to choose?

Consideration Local (-D) Global (-g)
Version pinned per project Yes No — one shared version
Reproducible builds / CI Yes Not reliably
Available in any folder Only via npx Yes, everywhere
Best for Real projects, teams Quick tests, learning

For anything you'll maintain or ship, prefer the local install. Reach for global only when you want a throwaway sass command.

Using watch mode and multiple files

Watch mode is what makes the day-to-day workflow pleasant. Instead of compiling by hand, Sass listens for changes:

sass --watch scss:css

The scss:css syntax compiles every .scss file in the scss folder into a matching file in the css folder — no need to name each file. This folder-to-folder mapping is the most common setup for a real project.

Useful CLI flags

Flag What it does
--watch Recompile automatically when files change
--style=compressed Minify output for production
--no-source-map Skip the .map file
--load-path=<dir> Add a directory to the @use/@import search path
--help List every option

For a production build, compress the output:

sass scss/main.scss css/main.css --style=compressed --no-source-map

By default Sass emits an expanded, readable stylesheet plus a source map, which is exactly what you want during development.

Method 3: Let your build tool handle Sass

Most modern front-end tooling can compile Sass for you, so you often don't run the CLI directly at all. In these setups you still install the sass package — the bundler calls it under the hood.

The rule of thumb: if you already use a bundler, install sass as a dev dependency and let the bundler drive it. Save the standalone CLI for static sites or plain HTML projects without a build step.

Verify your install and compile your first file

Confirm the compiler is working:

sass --version

You should see a version number (Dart Sass releases are numbered like 1.x.x). Then create a tiny test file, scss/main.scss:

$brand: #2f6f4f;

.button {
  padding: 0.75rem 1.25rem;
  background: $brand;
  border-radius: 6px;

  &:hover {
    background: darken($brand, 8%);
  }
}

Compile it:

npx sass scss/main.scss css/main.css

Open css/main.css and you'll see the nested rule flattened into standard CSS with the variable substituted in. That confirms the whole pipeline works.

Note: darken() and the other global color functions still work, but modern Sass recommends the color.adjust() and color.scale() functions from the built-in sass:color module. The one-liner above is fine for a smoke test; reach for the module functions in real code.

Common install problems

Where to go next

Once Sass compiles, the payoff is in the features: variables, nesting, partials, mixins, and the module system. Work through the complete guide to Sass to put your new setup to use, and if you're weighing your whole toolchain, compare the options in CSS preprocessors vs PostCSS. You can also browse more setup and build articles in Tooling & Workflow.

The short version stays true no matter how deep you go: npm install -D sass, point the CLI at your source file, and add --watch while you work.

FAQ

How do I install Sass with npm?

Run npm install --save-dev sass inside your project folder. This installs Dart Sass as a dev dependency and records it in package.json. Compile with npx sass scss/main.scss css/main.css, or add npm scripts so you can run npm run sass. The --save-dev flag is correct because Sass is a build tool, not a runtime dependency your shipped site needs.

What is the difference between sass and node-sass?

The sass package is Dart Sass, the official and actively maintained implementation with the modern @use and @forward module system. node-sass wraps the deprecated LibSass engine, which no longer receives new Sass features. Always install sass for new projects, and migrate existing node-sass projects to sass to keep using current syntax.

How do I compile SCSS to CSS?

Point the Sass CLI at your source and output files: sass input.scss output.css. Add --watch to recompile automatically on save, and use folder syntax like sass --watch scss:css to compile a whole directory. For production, add --style=compressed to minify the output. With a bundler like Vite or webpack, importing an .scss file compiles it for you.

Do I need Node.js to install Sass?

Not necessarily. The npm methods (npm install sass) need Node.js, but Dart Sass also ships as a standalone executable. Install it with Homebrew on macOS (brew install sass/sass/sass), Chocolatey on Windows (choco install sass), or by downloading a standalone archive from the Dart Sass GitHub releases page. All give you the same sass command.

How do I install Sass globally?

Run npm install -g sass to make the sass command available in any folder without npx. Global installs are convenient for quick experiments and learning, but for real projects prefer a local dev dependency so the Sass version is pinned per project and your builds stay reproducible across teammates and CI.

How do I check if Sass is installed?

Run sass --version in your terminal. Dart Sass prints a version number like 1.x.x. If you installed locally with npm, use npx sass --version instead, since the binary lives in node_modules and is not on your global PATH. A command not found error usually means you installed locally and should use npx.