AI Generate Sass docs instantly

Sass Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Variables

2 snippets

Reusable values

Define & Use

$primary: #3b82f6;
$font-stack: 'Inter', sans-serif;
$spacing: 1rem;
$border-radius: 0.5rem;

.button {
  background: $primary;
  font-family: $font-stack;
  padding: $spacing;
  border-radius: $border-radius;
}

Default & Scope

$color: blue !default;  // Can be overridden

.component {
  $local: red;  // Only in this scope
  color: $local;
}

$global: green !global;  // Accessible everywhere

Nesting

2 snippets

Nested selectors and parent reference

Selectors

.nav {
  background: white;

  &__item {
    padding: 1rem;

    &--active {
      color: blue;
    }
  }

  &:hover {
    background: gray;
  }
}

@at-root

.parent {
  color: blue;

  @at-root .child {
    color: red;  // Not nested under .parent
  }
}

Mixins

3 snippets

Reusable style blocks

Basic Mixin

@mixin flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero {
  @include flex-center;
  min-height: 100vh;
}

With Arguments

@mixin responsive($breakpoint) {
  @if $breakpoint == mobile {
    @media (max-width: 768px) { @content; }
  } @else if $breakpoint == desktop {
    @media (min-width: 1024px) { @content; }
  }
}

.sidebar {
  width: 100%;
  @include responsive(desktop) {
    width: 300px;
  }
}

Default Args

@mixin button($bg: #3b82f6, $color: white, $radius: 0.5rem) {
  background: $bg;
  color: $color;
  border-radius: $radius;
  padding: 0.5rem 1rem;
}

.btn-primary { @include button; }
.btn-danger { @include button($bg: red); }

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Functions

2 snippets

Custom and built-in functions

Custom Function

@function rem($px) {
  @return calc($px / 16) * 1rem;
}

.title {
  font-size: rem(24);  // 1.5rem
  margin-bottom: rem(16);  // 1rem
}

Built-in

darken($primary, 10%)
lighten($primary, 20%)
mix(blue, red, 50%)
percentage(0.5)     // 50%
round(4.7)          // 5
min(100px, 50vw)
str-length("hello") // 5

Control Flow

3 snippets

Conditionals and loops

@if / @else

@mixin theme($mode) {
  @if $mode == dark {
    background: #1a1a1a;
    color: white;
  } @else {
    background: white;
    color: #1a1a1a;
  }
}

@each

$sizes: (sm: 0.875rem, md: 1rem, lg: 1.25rem, xl: 1.5rem);

@each $name, $size in $sizes {
  .text-#{$name} {
    font-size: $size;
  }
}

@for

@for $i from 1 through 12 {
  .col-#{$i} {
    width: percentage(calc($i / 12));
  }
}

Modules

3 snippets

@use and @forward

@use

// _variables.scss
$primary: blue;

// main.scss
@use 'variables';
.button { color: variables.$primary; }

// With namespace
@use 'variables' as v;
.button { color: v.$primary; }

@forward

// _index.scss (barrel file)
@forward 'variables';
@forward 'mixins';
@forward 'functions';

// main.scss
@use 'index';

Configure

// Override defaults
@use 'library' with (
  $primary: #22c55e,
  $border-radius: 8px
);

More Cheat Sheets

FAQ

Frequently asked questions

What is a Sass cheat sheet?

A Sass cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Sass. It helps developers quickly look up syntax without searching through documentation.

How do I learn Sass quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Sass concepts?

Key Sass concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Sass code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Sass code using AI.

Related resources

Stop memorizing. Start shipping.

Generate Sass Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week