Sass

Math

@use 'sass:math';
$button-height: 30px;
button {
    height: $button-height;
    width: $button-height * 2;
    border-radius: math.div($button-height, 2);
}

Property nesting

animation: {
  duration: 0.5s;
  timing-function: linear;
  iteration-count: infinite;
  direction: alternate;
  fill-mode: both;
  name: bounce;
}

@for (repetition)

@use 'sass:list';

@for $i from 1 to 10 {
    &:nth-child(#{$i}) {
        // use list.slash because / will perform division
        grid-area: list.slash($i, $i);
    }
}

Reusing Rules

@extend

.error {
    background-color: red;
    &--serious {
        @extend .error;
    }
}
.error, .error--serious {
    background-color: red;
}
Warning

@extend cannot be used across at-rule boundaries! Use #@mixin and @include instead.

Placeholder selectors

%danger {
    background-color: red;
}

.error {
    @extend %danger;
}

@mixin and @include

@mixin danger {
    background-color: red;
}

.error {
    @include danger;

    &--serious {
        @include danger;
    }
}
.error {
    background-color: red;
}

.error--serious {
    background-color: red;
}

See also