TExcelTAD
Home › Sass › Sass Comments

Sass Comments

Sass supports three kinds of comments. They differ in whether they appear in the compiled CSS — which matters for licence headers, documentation and file size.

Syntax Name In expanded CSS? In compressed CSS?
// … Silent comment Never Never
/* … */ Loud comment Yes No (removed)
/*! … */ Preserved comment Yes Yes
/// … Documentation comment Never Never

Silent and loud comments

scss · try it yourself
// This note is only for people reading the .scss file.
$brand: #cc6699; // inline silent comment

/* Buttons
   ------- */
.btn {
  background: $brand; /* loud comment after a declaration */
}

/*! Theme v2.1 - MIT License */
/* Buttons
   ------- */
.btn {
  background: #cc6699; /* loud comment after a declaration */
}

/*! Theme v2.1 - MIT License */

All // comments vanished. Both /* */ comments were kept in expanded output; with --style=compressed, only the /*! */ one would remain.

Tip: Use // for almost everything. Use /*! … */ only for text that legally or practically must ship with the CSS, such as a licence header.

Interpolation in loud comments

Loud comments are output as CSS, so Sass evaluates #{} inside them. That's handy for stamping values into the output:

scss · try it yourself
$version: "2.4.0";
$columns: 12;

/* Generated grid: #{$columns} columns, build #{$version} */
.row {
  display: flex;
}
/* Generated grid: 12 columns, build 2.4.0 */
.row {
  display: flex;
}

Documentation comments

Triple-slash comments document mixins, functions and variables. Tools like SassDoc read them to generate reference pages, and editors show them on hover:

scss · try it yourself
@use "sass:math";

/// Converts a pixel value to rem.
/// @param {Number} $px - Size in pixels
/// @param {Number} $base [16px] - Root font size
/// @return {Number} Size in rem
@function rem($px, $base: 16px) {
  @return math.div($px, $base) * 1rem;
}

.lead {
  font-size: rem(20px);
}
.lead {
  font-size: 1.25rem;
}

Commenting out code

// is the quickest way to disable lines while experimenting. Unlike plain CSS, you can comment out a single declaration without wrapping it in /* */:

scss
.card {
  padding: 16px;
  // box-shadow: 0 2px 8px rgb(0 0 0 / 0.2);
  border-radius: 8px;
}

Note: In plain .css files, // is not a comment — it makes the browser drop the next declaration. It's only valid in .scss files because Sass removes it before the browser sees anything.

Good commenting habits

  • Explain why, not what: // Matches the header height so the anchor isn't hidden beats // margin top 64.
  • Mark sections in long files with a consistent banner, e.g. // === Layout ===.
  • Document every public mixin and function with ///.
  • Delete commented-out code before committing; version control remembers it.

Test yourself

Which comment is never included in the compiled CSS?

  1. /* comment */
  2. /*! comment */
  3. // comment
  4. All are included

Which comment survives --style=compressed?

  1. // note
  2. /* note */
  3. /*! note */
  4. /// note

What are /// comments used for?

  1. Loud comments
  2. Documentation read by tools like SassDoc
  3. Disabling @use rules
  4. Preserved licence headers