SCSS Formatter
Format SCSS — nesting, mixins, maps and control directives — with Prettier, without compiling anything.
Your SCSS
Formatted SCSS
SCSS files drift out of shape faster than plain CSS because there is so much more shape to lose. Nesting depth communicates structure, so a block indented at the wrong level actively misleads you about which selector it belongs to. A Sass map written across one long line is unreadable; the same map with one entry per line is a lookup table. And @each loops, @if branches and mixin definitions all carry braces that need to line up before you can trust what you are reading.
This page runs Prettier 3.9.6 with its SCSS parser configuration, in your browser. Prettier discards your existing line breaks and reprints the file from its parse tree, which is what makes the output consistent across a whole team. It is a formatter only: it does not compile SCSS to CSS, does not resolve @use or @import, and does not evaluate a single variable or function call.
How to use the scss formatter
- 1
Paste your SCSS partial or entry file
Paste, drop a
.scssfile on the pane, or use Upload File. Partials that start with@useand reference variables defined elsewhere format fine — nothing needs to resolve, because nothing is evaluated. - 2
Choose indentation
Two spaces is the Sass community default and what most style guides assume. Four spaces and tabs are available if your project standard differs. Nested blocks indent by one unit per level.
- 3
Copy the result back into your editor
Copy SCSS gives you plain text; Download SCSS saves a
.scssfile. If your repository already runs Prettier in a pre-commit hook, the output here should match it exactly, provided the versions agree.
SCSS constructs the formatter understands
The SCSS parser covers the full modern Sass language, not just CSS with nesting:
- The module system.
@use,@forward, namespace prefixes such ast.$brand,withconfiguration blocks, and the built-in modulessass:map,sass:math,sass:colorand friends. - Nesting and the parent selector. Ordinary nesting,
&__elementand&--modifierBEM suffixes, and the inverted form.parent & { … }that reaches outward. - Mixins and functions.
@mixin,@includewith a trailing content block,@content,@functionwith@return, default parameter values, and argument lists that wrap when long. - Control directives.
@if/@else if/@elsechains,@eachover lists and maps with destructured$key, $valuepairs,@forloops and@while. - Placeholders and extension.
%placeholderselectors and@extend. - Interpolation.
#{$name}inside selectors, property names, values, media queries and strings. - Flags and directives.
!default,!global,@error,@warnand@debug.
Sass maps get the treatment that matters most: a map with several entries is printed one entry per line with the closing parenthesis on its own line, so it reads like the data structure it is instead of a wall of commas.
Comments behave differently from plain CSS
SCSS supports two comment styles and they mean different things. A /* … */ block comment is a CSS comment and survives compilation into the output stylesheet. A // … line comment is a Sass comment and is stripped by the compiler before any CSS is produced.
Both are preserved here, exactly as written, because a formatter that deleted your comments would be worse than no formatter. What Prettier will change is their surrounding whitespace: a comment on its own line stays on its own line, a trailing comment stays trailing, and runs of blank lines around them collapse to at most one.
One thing to watch: since // comments never reach the compiled CSS, they are the right place for notes to other developers, while /*! … */ is the right form for a licence banner that must ship. The formatter respects the distinction rather than normalising one into the other.
What formatting cannot tell you
Because nothing is compiled, this page cannot tell you whether your SCSS actually works. A reference to $brand that was never defined, a call to map.get() on a variable that is not a map, an @use pointing at a file that does not exist, or a mixin invoked with the wrong number of arguments will all format perfectly and then fail the moment you run sass. Formatting is a syntax operation; those are semantic errors that need the whole dependency graph.
Genuine syntax errors — an unclosed brace, a mixin definition missing its parameter list, an @if with no condition — are reported with the line and column where the parser gave up.
Nothing is uploaded. The parser runs in a Web Worker on your own machine, which is worth knowing given how often internal design-system source contains unreleased product names in its variable names.
SCSS Formatter FAQ
Does this compile SCSS into CSS?
No. It formats SCSS source and returns SCSS source. Compilation requires the Dart Sass engine plus every file your @use and @import rules reference, which a single-file browser tool cannot resolve. Run sass locally for that.
Will it work with the indented .sass syntax?
No. Prettier supports the brace-and-semicolon SCSS syntax only. The older indented Sass syntax, with no braces or semicolons, is a different grammar and will fail to parse here.
Are my // comments kept?
Yes. Both // Sass comments and /* … */ CSS comments are preserved with their content and position intact. Only the blank lines around them may be normalised.
Why did my carefully aligned map get reflowed?
Prettier prints from the syntax tree, so manual alignment — padding keys with spaces so the values line up in a column — is not preserved. In exchange you get output that is identical no matter who formats the file or what state it was in beforehand.
Can I format plain CSS here too?
Yes. SCSS is a superset of CSS, so valid CSS parses as valid SCSS. The CSS formatter is still the better choice for pure CSS, since it uses the parser matched to that dialect.
