Skip to content
Sass

Functions

Define custom functions that return computed values.

#functions#logic

Code

sass
@function rem($px, $base: 16px) {
  @return ($px / $base) * 1rem;
}

@function strip-unit($value) {
  @return $value / ($value * 0 + 1);
}

.title {
  font-size: rem(24px);    // 1.5rem
  padding: rem(16px);
}

.container {
  max-width: rem(960);
}

// Built-in functions: lighten, darken, transparentize,
// mix, map-get, str-length, unit, etc.