Skip to content

Sass Functions & Directives API

Sass built-in functions for color manipulation and the @mixin/@include/@extend control directives.

2 classes · 8 methods

Functions

4 methods

Sass color functions for adjusting lightness and mixing colors. Operate on Sass color values at compile time.

lighten($color, $amount)

Returns a color lightened by $amount (0%-100%) in HSL lightness.

Parameters

NameTypeDescription
$colorcolorBase color.
$amountpercentage (0-100%)Amount to lighten.

Returns

color

Example

sass
$base: #3498db;
.hover {
  background: lighten($base, 10%);
}
darken($color, $amount)

Returns a color darkened by $amount (0%-100%) in HSL lightness.

Parameters

NameTypeDescription
$colorcolorBase color.
$amountpercentage (0-100%)Amount to darken.

Returns

color

Example

sass
$base: #3498db;
.active {
  background: darken($base, 10%);
}
mix($color1, $color2, $weight: 50%)

Mixes two colors together, with $weight indicating how much of $color1 to use.

Parameters

NameTypeDescription
$color1colorFirst color.
$color2colorSecond color.
$weightpercentage (0-100%)Proportion of $color1 (default 50%).

Returns

color

Example

sass
$brand: mix(#ff0000, #0000ff, 60%);
// ~ #990099
rgba($color, $alpha)

Returns the given color with the specified alpha channel (opacity).

Parameters

NameTypeDescription
$colorcolorBase color.
$alphanumber (0-1)Alpha value.

Returns

color

Example

sass
.overlay {
  background: rgba(#000, 0.5);
}

Directives

4 methods

Sass control directives @mixin, @include, and @extend for reusable styles and selector inheritance.

@mixin name($args...) { ... }

Defines a reusable block of styles that can accept arguments. Invoked with @include.

Parameters

NameTypeDescription
nameidentifierMixin name.
argsanyOptional parameters with defaults.

Returns

mixin definition

Example

sass
@mixin button($bg: blue) {
  background: $bg;
  padding: 8px 16px;
  border-radius: 4px;
}
@include name($args...)

Includes a previously defined mixin, optionally passing arguments.

Parameters

NameTypeDescription
nameidentifierMixin name to include.
argsanyArguments matching the mixin signature.

Returns

styles

Example

sass
.cta {
  @include button(red);
}
@extend %placeholder | .selector

Inherits the styles of another rule or placeholder, inserting the extending selector alongside the source.

Parameters

NameTypeDescription
%placeholder | .selectorselectorPlaceholder or class selector to extend.

Returns

styles

Example

sass
%card {
  border: 1px solid #ccc;
  border-radius: 6px;
}
.error-card {
  @extend %card;
  border-color: red;
}
@include name { content }

Passes a block of styles to a mixin via @content; useful for media-query wrappers.

Returns

styles

Example

sass
@mixin respond-to($bp) {
  @media (min-width: $bp) { @content; }
}
.sidebar {
  @include respond-to(768px) {
    width: 240px;
  }
}