Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 39 ยท Getting Started

SCSS and the Indented Sass Syntax

Compare the two Sass syntaxes, SCSS with braces and the indented .sass format without them, see the same stylesheet in both, and learn which one to choose.

Sass comes in two flavors that share every feature. SCSS (Sassy CSS, files ending in .scss) looks like CSS: braces, semicolons, and the same nesting you know. The indented syntax (files ending in .sass) is the original format. It removes braces and semicolons and uses line breaks and indentation, a bit like Python or Pug.

People often say "Sass" when they mean SCSS, which makes the topic confusing. Here is the short version: the language is called Sass, and it has two syntaxes. Both compile to identical CSS, and you can even mix files of both kinds in one project.

The same stylesheet, twice

SCSS:

SCSS
$brand: #0ea5e9;

@mixin center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero {
  @include center;
  background: $brand;

  h1 {
    color: white;
  }
}

Indented syntax:

SASS
$brand: #0ea5e9

=center
  display: flex
  align-items: center
  justify-content: center

.hero
  +center
  background: $brand

  h1
    color: white

Differences you can see right away:

  • No braces. Indentation (spaces or tabs, but be consistent) defines what is inside what.
  • No semicolons. A newline ends a declaration.
  • = defines a mixin and + includes it. These are shorthands for @mixin and @include. The long forms also work in .sass files.
  • Comments with // work in both, but multi-line /* */ comments need careful indentation in the indented syntax.
Compile both syntaxes

The syntax: "indented" option is only needed with compileString. The command line and bundlers pick the syntax from the file extension.

Which one should you use?

Choose SCSS unless you have a strong reason not to:

  • Every CSS snippet you find online pastes straight in.
  • Editors, linters (such as Stylelint), formatters and tutorials assume SCSS.
  • Migrating an existing CSS project is just renaming files.

The indented syntax is perfectly valid and some teams love its brevity, especially people who already write Pug, Slim or Haml. Its downsides are the smaller ecosystem, a harder time pasting CSS, and whitespace sensitivity. This tutorial uses SCSS from here on.

Differences to watch for in .sass files

Some SCSS features need a different spelling in the indented syntax:

Feature SCSS Indented
Block a { color: red; } a then color: red on the next, indented line
Mixin @mixin foo { ... } =foo
Include @include foo; +foo
Multi-line value spans lines freely must end lines with a comma, or the value is cut
Long selector list commas anywhere a trailing comma continues the list
SASS
.alert,
.notice
  padding: 1rem

Because a newline ends a declaration, a long value must be wrapped in brackets or broken after a comma. font-family: followed by a list that continues on the next line only works if the line ends with a comma.

Mixing syntaxes in one project

Sass decides how to parse each file by its extension, so a project can contain _tokens.sass and main.scss side by side. The @use rule does not care which syntax the other file uses, and you leave the extension off in the path:

SCSS
@use "tokens";   // finds _tokens.sass or _tokens.scss

Mixing is allowed but confusing, so teams usually pick one. If you inherit .sass files and want SCSS, rename them and add braces and semicolons; many editors and online converters can do that automatically.

Plain CSS files can be loaded as well: @use "reset" will pick up reset.css if there is no .scss or .sass file with that name. Plain CSS files cannot contain Sass features, of course.

A quick tour of SCSS rules you will use in every file

Because SCSS is CSS plus extras, these three details cause most of the early surprises:

  1. Semicolons matter. The last declaration in a block can omit its semicolon, but always writing it avoids bugs when you add a line later.
  2. Nested blocks come from the parent. a { b { c: d } } compiles to a b { c: d }. Nesting covers every nuance.
  3. Comments differ. /* */ survives into the CSS (unless compressed), while // is removed. See Comments and output styles.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which statement is true about SCSS and the indented syntax?

    Both syntaxes are two ways of writing the same language, and both produce identical CSS.
  2. 2. How do you include a mixin named center in the indented syntax?

    • is shorthand for @include in the indented syntax. = is shorthand for @mixin, and @include also works if you prefer the long form.
  3. 3. Why is SCSS the more common choice?

    SCSS is a superset of CSS, so any valid CSS is valid SCSS. The indented syntax is still supported.
  4. 4. With compileString, how do you compile indented-syntax source?

    A string has no file extension, so you tell the compiler the syntax with the syntax option. Files use their extension.

Summary

  • Sass has two syntaxes: SCSS (braces and semicolons) and the indented syntax (indentation only).
  • Both have the same features and produce the same CSS; = and + are indented shorthands for @mixin and @include.
  • SCSS is the default choice because it is a CSS superset with the broadest tooling.
  • Files choose their syntax by extension, and @use works across both.
  • With compileString, pass syntax: "indented" for .sass-style source.

Next: Comments and output styles