What does % mean in SASS?

https://sass-lang.com/documentation/style-rules/placeholder-selectors

Placeholder Selectors: %foo

Sass supports a special type of selector called a “placeholder
selector”. These look like class and id selectors, except the # or .
is replaced by %. They’re meant to be used with the @extend directive;
for more information see @extend-Only Selectors.

On their own, without any use of @extend, rulesets that use
placeholder selectors will not be rendered to CSS.

Example

SCSS SYNTAX

    %toolbelt {
      box-sizing: border-box;
      border-top: 1px rgba(#000, .12) solid;
      padding: 16px 0;
      width: 100%;
    
      &:hover { border: 2px rgba(#000, .5) solid; }
    }
    
    .action-buttons {
      @extend %toolbelt;
      color: #4285f4;
    }
    
    .reset-buttons {
      @extend %toolbelt;
      color: #cddc39;
    }

CSS Output

    .action-buttons, .reset-buttons {
      box-sizing: border-box;
      border-top: 1px rgba(0, 0, 0, 0.12) solid;
      padding: 16px 0;
      width: 100%;
    }
    .action-buttons:hover, .reset-buttons:hover {
      border: 2px rgba(0, 0, 0, 0.5) solid;
    }

    .action-buttons {
      color: #4285f4;
    }
    
    .reset-buttons {
      color: #cddc39;
    }

Leave a Comment