OnlineCBT Logo OnlineCBT
CSS Tutorial
CSS · LESSON 45

Sass and SCSS Preprocessor Fundamentals

By Ratan Updated: 15 Oct 2026

Introduction to SCSS syntax, nesting, variables, mixins, and modular stylesheets.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Compile authoring syntax into browser CSS

Sass is a stylesheet preprocessor. SCSS is its CSS-like syntax. Browsers consume the compiled CSS, not an .scss source file. Use preprocessing for clear reuse and organization, while keeping the generated output understandable.

// styles.scss
$brand: #1d4ed8;
@mixin focus-ring {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}
.button {
  background: $brand;
  color: white;
  &:focus-visible { @include focus-ring; }
}

The variable is resolved during compilation. The ampersand refers to the current parent selector, producing .button:focus-visible. A mixin includes reusable declarations at each invocation; it does not create a runtime function.

Build workflow

With Sass installed through the project's approved tooling, compile using a command such as sass styles.scss styles.css, then link styles.css in HTML. Watch mode can rebuild on edits. Keep generated files and source maps organized according to the existing project's build setup.

Modules and nesting

Modern Sass modules use @use and @forward. Do not start a new module system around the older @import pattern without checking the current official guidance. Keep nesting shallow: deeply nested selectors tightly couple styles to wrapper structure and increase specificity.

Sass variables versus custom properties

A Sass variable is resolved at build time. A CSS custom property remains in the browser and participates in runtime cascade and theming. Use custom properties for per-component or theme values that must change without recompilation; preprocessing and native CSS can work together.

Practice

  1. Compile the sample and inspect the resulting plain CSS.
  2. Change $brand and rebuild; the browser changes only after the generated stylesheet changes.
  3. Extract a focus-ring mixin and use it on a button and input.
  4. Replace a deeply nested selector with a component class and compare the generated specificity.

Reference: official Sass guide.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat