Compile SCSS to CSS in the browser: variables,
nesting, mixins, @extend and functions. Use it to
check what a snippet produces without starting a build.
Variables, nesting, mixins, @extend, functions, @if and @each, and the global helpers such as darken() and percentage(). The compiler is Sass.js, a JavaScript build of LibSass, so the newer module system (@use, sass:math, math.div()) is not available.
@import of your own files fails, because there is no project directory here. Paste the partials inline, or compile locally with Dart Sass.
// Variables
$primary-color: #3b82f6;
$font-stack: Helvetica, sans-serif;
// Mixin
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
// Nesting & Usage
body {
font: 100% $font-stack;
color: $primary-color;
.container {
width: 100%;
@include border-radius(10px);
a {
text-decoration: none;
&:hover {
color: darken($primary-color, 10%);
}
}
}
} Confirm newer syntax in Dart Sass before you rely on it. Compilation runs in the page with LibSass, which gives the same CSS as Dart Sass for everyday SCSS: nested rules are flattened, variables are resolved, and nothing browser-specific is added. However, LibSass is deprecated and stopped at an older version of the language, so output can differ on features added since.
// npm i sass
const sass = require("sass");
const scss = `
$primary: #3490dc;
.btn {
color: $primary;
&:hover { color: darken($primary, 10%); }
}
`;
const result = sass.compileString(scss, { style: "expanded" }); // or "compressed"
console.log(result.css);
// Compile a file, resolving @use and @import relative to it:
// sass.compile("src/main.scss", { style: "compressed" }).css
// From the shell: npx sass src/main.scss dist/main.css --style=compressed The sass npm package is the reference Dart Sass implementation. node-sass (LibSass) is deprecated and lacks newer features such as @use, and so does the LibSass build this page runs.
<?php
// composer require scssphp/scssphp
require 'vendor/autoload.php';
use ScssPhp\ScssPhp\Compiler;
use ScssPhp\ScssPhp\OutputStyle;
$compiler = new Compiler();
$compiler->setOutputStyle(OutputStyle::EXPANDED); // or COMPRESSED
$compiler->setImportPaths(__DIR__ . '/scss'); // where @use / @import look
$scss = '$primary: #3490dc; .btn { color: $primary; &:hover { color: darken($primary, 10%); } }';
echo $compiler->compileString($scss)->getCss(); scssphp is a pure PHP port and lags behind Dart Sass on some newer functions. Check its changelog if a built-in function is missing.
# pip install libsass
import sass
scss = """
$primary: #3490dc;
.btn {
color: $primary;
&:hover { color: darken($primary, 10%); }
}
"""
print(sass.compile(string=scss, output_style="expanded"))
# Whole directory:
# sass.compile(dirname=("scss", "css"), output_style="compressed") libsass is deprecated and never got Sass modules (@use). For new work, call the Dart Sass CLI instead.
SCSS adds variables, nesting, mixins, functions and partials on top of CSS syntax. The browser never sees any of it: a compiler flattens it to plain CSS at build time, so it costs nothing at runtime. Native CSS nesting and custom properties have covered much of the same ground since 2023, and mixins and build-time functions are what still need Sass.
Sass has two syntaxes. SCSS, the one this tool compiles, uses braces and semicolons and is a superset of CSS. The older indented syntax (.sass files) drops the punctuation in favor of indentation. Dart Sass handles both and picks the parser from the file extension.
This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.
Variables, nesting, mixins, functions, @extend, and control directives such as @if and @each. The compiler is Sass.js, a JavaScript build of LibSass, so the newer module system (@use, sass:math, math.div()) is not supported.
No. There is no file system, so @import of your own partials cannot be resolved; paste their contents into the editor instead. @use is not available at all, because LibSass never implemented it.
Yes. The compiled CSS is beautified with the indentation you pick (2 Spaces, 4 Spaces or Tab). Click Minify afterward for a compact version.
No. The compiler reads SCSS syntax, with braces and semicolons. Convert indented syntax to SCSS first.
The Sass.js compiler is LibSass compiled to JavaScript, a large script that loads with the page. Once it has loaded, each compile runs locally in your tab.
The CSS formatter tidies or minifies the output, and Purge CSS drops the rules your markup never uses.