Sass Introduction

What Is Sass?
Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor. You write Sass or SCSS source files; a compiler turns them into standard CSS that browsers load as usual.
Author → styles.scss (variables, nesting, mixins)
Compile → styles.css (plain CSS for the browser)
Two syntaxes:
.scss → SCSS (CSS-compatible; most common)
.sass → indented Sass (no braces)
Prefer @use over legacy @import in new projects Any valid CSS file is valid SCSS. Learn CSS first—Sass extends it with variables, nesting, mixins, and modules so large stylesheets stay organized.
Why Use Sass?
Plain CSS works, but repeating colors and deep selectors gets messy. Sass adds structure without changing what the browser understands.
| Need | How Sass helps |
|---|---|
| Reuse values | Variables like $primary-color |
| Readable selectors | Nest rules instead of repeating parents |
| Share patterns | Mixins and @extend / placeholders |
| Split files | Partials and @use modules |
How Sass Becomes CSS
Browsers never run SCSS—only the compiled CSS ships:
| Step | What happens |
|---|---|
| 1. Write | You author .scss (or .sass) with Sass features |
| 2. Compile | Dart Sass or a bundler expands variables, nesting, and mixins |
| 3. Output | A plain .css file (optionally minified / sourcemapped) |
| 4. Serve | HTML links the CSS; the browser styles the page |
Your First SCSS File
Variables plus nesting—then compile to CSS:
$primary-color: #333;
body {
font: 100% Helvetica, sans-serif;
color: $primary-color;
}
nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
li { display: inline-block; }
a {
display: block;
padding: 6px 12px;
text-decoration: none;
}
} sass styles.scss styles.css body {
font: 100% Helvetica, sans-serif;
color: #333;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
}
nav a {
display: block;
padding: 6px 12px;
text-decoration: none;
} How It Works
1. Variable. $primary-color stores a value you reuse.
2. Nesting. Rules inside nav compile to nav ul, nav a, and so on.
3. Compile. sass (or Vite / Webpack) emits plain CSS for production.
Next, set up the toolchain in Sass Installation.
Sass vs Plain CSS
Sass is a super-set workflow—CSS is still the deliverable:
| Sass / SCSS | Plain CSS |
|---|---|
| Authoring language + compiler | What the browser loads |
| Variables, nesting, mixins, modules | Native custom properties & nesting (newer) |
Needs a build step for .scss | Can ship without a preprocessor |
| Great for large design systems | Fine for small pages and prototypes |
When to use which
| Use Sass when… | Prefer plain CSS when… |
|---|---|
| You share tokens, mixins, and many partials | The project is tiny or build-free |
| The team already has a Sass design system | You only need modern CSS features |
| You maintain a large legacy SCSS codebase | You want zero compile tooling |
Core Building Blocks
These features show up in almost every Sass project:
| Feature | What it does | Example |
|---|---|---|
| Variables | Store reusable values | $gap: 1rem; |
| Nesting | Nest selectors to match HTML | nav { a { } } |
| Partials | Split styles into _file.scss | @use "variables"; |
| Mixins | Reusable chunks of CSS | @include flex-center; |
| Operators | Math on numbers and colors | width: 100% / 3; |
| Functions | Built-in color/string/math helpers | lighten($c, 10%) |
Where Is Sass Used?
Sass still powers many front-end stacks:
| Use case | Why Sass fits |
|---|---|
| Design systems | Shared tokens, mixins, and theme maps |
| Component libraries | Partials per component, consistent spacing |
| Responsive layouts | Breakpoint mixins and fluid math |
| Legacy apps | Large SCSS codebases still in production |
| Framework themes | Bootstrap and others ship Sass sources |
| Static sites | Compile once, ship plain CSS |
Key Takeaways
- Sass is a preprocessor—browsers only see CSS.
- SCSS is the usual syntax; any CSS is valid SCSS.
- Core tools: variables, nesting, mixins, and
@use. - Learn CSS first—Sass organizes it; it does not replace it.
One line: Sass writes smarter CSS—next, install the compiler.
Frequently Asked Questions
Did you know?
Write SCSS in .scss files (CSS-compatible syntax). Compile to CSS with sass styles.scss styles.css or your build tool. Prefer @use over legacy @import in new projects.
Next: Sass Installation
Install the compiler and turn SCSS into CSS on your machine.
10 people found this page helpful
