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
// 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:
$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:
@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 /* */:
.card {
padding: 16px;
// box-shadow: 0 2px 8px rgb(0 0 0 / 0.2);
border-radius: 8px;
}Note: In plain
.cssfiles,//is not a comment — it makes the browser drop the next declaration. It's only valid in.scssfiles 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 hiddenbeats// 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?
- /* comment */
- /*! comment */
- // comment
- All are included
Which comment survives --style=compressed?
- // note
- /* note */
- /*! note */
- /// note
What are /// comments used for?
- Loud comments
- Documentation read by tools like SassDoc
- Disabling @use rules
- Preserved licence headers