Sass Tutorial
Learn Sass step by step: 39 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- Introduction to Sass Learn what Sass is, how it extends CSS with variables, nesting, mixins and functions, and why teams compile Sass into plain CSS for the browser.
- Installing and Compiling Sass Install Dart Sass with npm or a standalone binary, compile SCSS from the command line with --watch, and call the JavaScript API from your own code.
- SCSS and the Indented Sass Syntax Compare the two Sass syntaxes, SCSS with braces and the indented .sass format without them, see the same stylesheet in both, and learn which one to choose.
- Sass Comments and Output Styles Learn silent // comments, loud /* */ comments, the /*! */ license form, expanded versus compressed CSS, @charset handling and how source maps help debugging.
Variables, Nesting and Partials
- Sass Variables Master Sass variables: declare values with $, reuse them everywhere, understand scope, !default and !global flags, and combine them with CSS custom properties.
- Sass Data Types and Operators Learn the seven Sass data types, arithmetic with units, comparison and logical operators, string concatenation and why you use math.div instead of the slash.
- Sass Nesting and the Parent Selector (&) Write cleaner CSS with Sass nesting: nested selectors and combinators, the & parent selector, nested properties and media queries, @at-root and depth limits.
- Sass Partials and the @use Rule Split a big stylesheet into partials and load them with @use: underscore file names, namespaces, aliases, private members, load order and why @import is deprecated.
- Sass @extend and Placeholder Selectors Learn how @extend shares rules between selectors, how %placeholder selectors avoid unused CSS, how @extend differs from mixins, and its limits and pitfalls.
- Sass Interpolation: The #{ } Syntax Use Sass interpolation to build selectors, property names, strings, media queries and custom property values from variables, and know when it is needed.
Mixins and Functions
- Sass Mixins with @mixin and @include Learn Sass mixins: define reusable style blocks with @mixin, apply them with @include, nest rules and the parent selector inside them, and organize mixin files.
- Sass Mixin Arguments and @content Blocks Make mixins flexible: parameters, default values, keyword and rest arguments, passing blocks of styles with @content, and content arguments with using.
- Writing Custom Sass Functions Write custom Sass functions with @function and @return: px to rem conversion, default arguments, rest arguments, validation with @error and when to use a mixin instead.
- Sass Color Functions: adjust, scale, mix and More Generate palettes with the sass:color module: adjust, scale, change, mix, complement and channel, plus how the old darken() and lighten() functions map to them.
- Sass Math, String and List Functions A practical tour of the sass:math, sass:string and sass:list modules: rounding, min and max, pow, slicing and splitting strings, and nth, append, join and zip.
Control Directives and Maps
- Sass @if, @else and Conditions Add logic to Sass with @if, @else if and @else: conditions, comparison and boolean operators, truthiness rules, conditional mixins and the modern inline if() function.
- Sass Loops: @each, @for and @while Generate repetitive CSS with Sass loops: @for with from, through and to, @each over lists and maps with destructuring, @while, loop scope and when not to loop.
- Sass Maps and the sass:map Module Store design tokens in Sass maps: syntax, map.get, has-key, merge and set, nested maps, iterating with @each and a breakpoint lookup that fails with a clear error.
- Building Spacing, Color and Type Scales in Sass A worked example that combines maps, loops, functions and color math: generate a spacing scale, a ten-step color palette and a modular type scale as CSS custom properties.
- Debugging Sass with @debug, @warn and @error Find and fix Sass problems: print values with @debug, raise warnings and errors in your own code, capture messages with a logger, handle deprecations and read common error messages.
Modules and Architecture
- Modules: @use and @forward Learn the Sass module system: load stylesheets with @use, control namespaces with as, re-export with @forward, and build index files without global scope pollution.
- Module Configuration, Defaults and load-css Configure Sass modules with !default and @use with, pass configuration through @forward, share placeholders across files, and load CSS dynamically with meta.load-css.
- Sass Built-in Modules (math, string, list, map, color, meta) A tour of Sass's built-in modules: sass:math, sass:string, sass:list, sass:map, sass:color, sass:selector and sass:meta, with live examples and the old global functions mapped to them.
- Project Architecture and the 7-1 Pattern Organize a Sass project with the 7-1 pattern, index files and layered entry points. Learn what goes in abstracts, base, layout and components, and how @use ties them together.
Real-world Patterns
- Design Tokens and Theming with Sass Build a design token system in Sass: store colors and spacing in maps, generate CSS custom properties with @each, validate tokens with @error, and ship light and dark themes.
- A Responsive Breakpoint System in Sass Create a reusable Sass breakpoint system: a breakpoints map, up, down and between mixins, container-query helpers, fluid sizing and safe error messages for unknown names.
- BEM and Component Patterns in Sass Write maintainable component styles with Sass: BEM with the & parent selector, @at-root, state classes, variant maps with @each, @content slots, and when to avoid nesting.
- Utility Class Generators with Sass Loops Generate utility classes with Sass maps, @each and @for: spacing scales, color helpers, responsive variants, a 12-column grid and an API map, while keeping output size under control.
Tooling and Build
- The Sass CLI, Watch Mode and Source Maps Install Sass and compile from the command line: file and folder mapping, --watch, output styles, load paths, source maps, quiet flags and npm scripts, with a live compiler.
- The Sass JavaScript API Use Sass from Node and the browser: compile, compileString, options, custom functions, custom importers, loggers and source maps, plus the removed legacy render API.
- Sass with Vite, webpack, PostCSS and Frameworks Wire Sass into modern build tools: Vite, webpack sass-loader, Laravel, Next.js and Angular, plus PostCSS autoprefixer and cssnano, additionalData, package imports and CSS Modules.
- Debugging Sass: @debug, @warn, @error and Common Errors Debug Sass like a pro: print values with @debug, raise warnings and errors in your own code, read compiler messages, fix the most common mistakes, and inspect values with meta.inspect.
Migration and Best Practices
- Migrating from @import to the Module System Move a legacy Sass codebase from @import and global functions to @use, @forward and built-in modules: why it matters, the sass-migrator tool, a manual plan, and traps to avoid.
- Sass Performance: Compile Speed and Output Size Speed up Sass builds and shrink the CSS you ship: use modules, sass-embedded, shallow nesting, mixins over extend, generator limits, gzip measurement and purging unused CSS.
- Sass Best Practices, Pitfalls and Sass vs Modern CSS A practical Sass style guide: naming, nesting limits, variables vs custom properties, documentation with SassDoc, common pitfalls, and an honest comparison of Sass with modern native CSS.
Projects and Practice
- Project: Build a Design System Stylesheet Build a small Sass design system from scratch: tokens, helper functions, mixins, configurable buttons and alerts, an index file with @forward, and a main file that ties it together.
- Project: A Themed Dashboard Layout Build a responsive dashboard stylesheet in Sass: theme maps turned into custom properties, a breakpoint mixin, a sidebar and card grid, stat tiles and a theme switch, step by step.
- Project: An Animated UI Kit with Sass Build a small animation toolkit in Sass: generate keyframes from a map, stagger list items with @for, add spinners and skeleton loaders, and respect prefers-reduced-motion.
- Sass Practice Set and Interview Questions Test your Sass skills with eight hands-on exercises with solutions and a set of common Sass interview questions on modules, mixins, maps, extend, performance and migration.