SCSS to CSS Compiler

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.

Input SCSS
Output CSS

1 What is supported

The SCSS language

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.

What it cannot do

@import of your own files fails, because there is no project directory here. Paste the partials inline, or compile locally with Dart Sass.

2 SCSS to CSS Compiler example

Example SCSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

// 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%);
      }
    }
  }
}

3 About the output

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.

How to use the SCSS to CSS Compiler tool

  1. Paste SCSS into the left editor, or click Upload File for a .scss or .css file. Dummy Data inserts a sample with variables, nesting and a mixin.
  2. The Sass engine loads with the page. If you click Compile before it is ready, the error reads "Sass compiler not loaded."; wait a moment and click again.
  3. Choose 2 Spaces, 4 Spaces or Tab from the indentation dropdown, then click Compile.
  4. The right panel shows plain CSS. If compilation fails, the error names the line in your SCSS, as in "Error line 4: ...".
  5. Click Minify to compress the compiled CSS, and Copy Output to copy it. Clear resets both panels.

How to compile SCSS to CSS in JavaScript, PHP and Python

JavaScript (Dart Sass)

// 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 (scssphp)

<?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.

Python (libsass)

# 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.

Common errors and how to fix them

Error: Undefined variable.
The variable is declared after it is used, or inside another block. Sass reads top to bottom, so move the declaration above the first use or make it global.
Error: Can't find stylesheet to import.
@import (or @use in Dart Sass) points to a file the compiler cannot reach. This page has no file system, so paste the partial's contents inline; LibSass reports it as "File to import not found or unreadable". In a build, add the folder to the include paths.
Error: expected "}".
A missing semicolon or closing brace earlier in the file. Sass reports the line where it gave up, which is often several lines below the real mistake.
Deprecation Warning: darken() is deprecated / Using / for division is deprecated
Dart Sass replaced these with color.adjust(), color.scale() and math.div(). The old forms still compile but will be removed, so run sass-migrator to update them. This page runs LibSass, which does not know the new module functions, so test migrated code with Dart Sass.
Compiled CSS is identical to the input
The file is plain CSS, or you pasted already-compiled output. SCSS is a superset of CSS, so valid CSS passes through unchanged.

Good to know

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.

Specifications and references

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.

Frequently Asked Questions

Which Sass features are supported?

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.

Can I use @import or @use?

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.

Is the output formatted?

Yes. The compiled CSS is beautified with the indentation you pick (2 Spaces, 4 Spaces or Tab). Click Minify afterward for a compact version.

Does it support the indented .sass syntax?

No. The compiler reads SCSS syntax, with braces and semicolons. Convert indented syntax to SCSS first.

Why does the page take a moment to become ready?

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.

Related

The CSS formatter tidies or minifies the output, and Purge CSS drops the rules your markup never uses.

More Code Formatters & Beautifiers

Browse all code formatters & beautifiers

Copied to clipboard!