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:
npm install --save-dev sassadded 17 packages, and audited 18 packages in 2s
found 0 vulnerabilities
Check the version that was installed:
npx sass --version1.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:
$accent: #cc6699;
body {
font-family: system-ui, sans-serif;
a { color: $accent; }
}Then compile it to CSS:
npx sass src/styles.scss dist/styles.cssNo 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:
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:
{
"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:
$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
.scssimports automatically oncesassis 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?
- node-sass
- sass
- dart-sass-loader
- scss
What does sass --watch src/scss:dist/css do?
- Compiles once and exits
- Recompiles files from src/scss into dist/css whenever they change
- Converts CSS back into SCSS
- Starts a web server
Which option minifies the generated CSS?
- --minify
- --style=compressed
- --production
- --no-source-map