TExcelTAD
Home › Sass › Sass Installation

Sass Installation

To use Sass in a real project you need the Dart Sass compiler. The easiest way to get it is the sass package from npm, which works on Windows, macOS and Linux. (The playgrounds on this site already include the compiler, so you can skip installing it while you learn.)

Option 1: install with npm

You need Node.js installed. Inside your project folder, add Sass as a development dependency:

bash · try it yourself
npm install --save-dev sass
added 17 packages, and audited 18 packages in 2s

found 0 vulnerabilities

Check the version that was installed:

bash · try it yourself
npx sass --version
1.105.2

Note: Do not install node-sass. It is based on the deprecated LibSass engine and doesn't support the module system (@use, sass:math, …).

Compiling a file

Create src/styles.scss:

scss
$accent: #cc6699;

body {
  font-family: system-ui, sans-serif;
  a { color: $accent; }
}

Then compile it to CSS:

bash
npx sass src/styles.scss dist/styles.css

No output means success — Sass is silent unless something goes wrong. The file dist/styles.css now contains plain CSS, plus a styles.css.map source map that lets browser dev tools show you the original .scss line.

Watch mode

Re-running the command after every change gets old quickly. --watch keeps Sass running and recompiles whenever a file changes:

bash · try it yourself
npx sass --watch src/styles.scss:dist/styles.css
[10:42:07] Compiled src/styles.scss to dist/styles.css.
Sass is watching for changes. Press Ctrl-C to stop.

The input:output form also works with whole folders: sass --watch src/scss:dist/css compiles every non-partial .scss file in src/scss.

Useful command-line options

Option What it does
--watch Recompile when files change
--style=compressed Minify the output (default is expanded)
--no-source-map Don't write a .map file
--load-path=node_modules Extra folder to search for @use targets
--silence-deprecation=import Hide a specific deprecation warning

npm scripts

Instead of typing long commands, put them in package.json:

json
{
  "scripts": {
    "sass:dev": "sass --watch src/scss:dist/css",
    "sass:build": "sass src/scss:dist/css --style=compressed --no-source-map"
  }
}

Now npm run sass:dev starts watching and npm run sass:build produces minified CSS for production.

Expanded vs compressed output

The compiler can format CSS in two styles. The playgrounds here always use expanded (readable) style:

scss · try it yourself
$gap: 16px;

.grid {
  display: grid;
  gap: $gap;
  .cell { padding: $gap * 0.5; }
}
.grid {
  display: grid;
  gap: 16px;
}
.grid .cell {
  padding: 8px;
}

With --style=compressed, the same code becomes a single line: .grid{display:grid;gap:16px}.grid .cell{padding:8px}.

Other ways to run Sass

  • Build tools — Vite, Webpack, Parcel and Astro compile .scss imports automatically once sass is installed (see the Sass with Vite lesson).
  • Editor extensions — e.g. "Live Sass Compiler" for VS Code compiles on save.
  • Standalone binary — download from the Dart Sass GitHub releases if you don't use Node.js.

Test yourself

Which npm package provides the official Dart Sass compiler?

  1. node-sass
  2. sass
  3. dart-sass-loader
  4. scss

What does sass --watch src/scss:dist/css do?

  1. Compiles once and exits
  2. Recompiles files from src/scss into dist/css whenever they change
  3. Converts CSS back into SCSS
  4. Starts a web server

Which option minifies the generated CSS?

  1. --minify
  2. --style=compressed
  3. --production
  4. --no-source-map