
SASS stands for Syntactically Awesome Style Sheets.
It is a CSS preprocessor that extends the capabilities of CSS (Cascading Style Sheets) by adding powerful features like variables, nesting, mixins, inheritance, and functions.
SASS helps developers write cleaner, reusable, and more efficient CSS code.
The SASS code is compiled (converted) into standard CSS so that browsers can read it.
๐ก What is a CSS Preprocessor?
A CSS preprocessor is a scripting language that adds advanced features to regular CSS.
Once the code is written, it must be compiled into plain CSS.
This process helps developers write dynamic and organized stylesheets for large projects.
๐งฑ Two Syntax Styles in SASS
- SASS Syntax (.sass)
- Older syntax.
- Uses indentation instead of curly braces
{}
and semicolons;
. - Cleaner and shorter.
$text-color: blue body color: $text-color
- SCSS Syntax (.scss)
- Newer and most commonly used syntax.
- Similar to regular CSS but with extra features.
- Uses curly braces
{}
and semicolons;
.
$text-color: blue; body { color: $text-color; }
โ๏ธ Basic Example (SCSS Syntax)
$primary-color: #3498db;
body {
background-color: $primary-color;
font-family: Arial, sans-serif;
h1 {
color: white;
text-align: center;
}
}
โ Explanation:
$primary-color
is a variable that stores a color value.- Nesting allows defining styles inside other selectors, following HTML structure.
- The SCSS code is compiled into normal CSS for the browser to use.
๐ Key Features of SASS
- Variables โ Store reusable values like colors, font sizes, etc.
- Nesting โ Write CSS rules inside one another for better structure.
- Mixins โ Create reusable groups of CSS properties.
- Inheritance (@extend) โ Share common styles between selectors.
- Partials and Imports โ Split code into multiple small files for organization.
- Operators โ Perform calculations within styles.
- Functions โ Create custom logic to generate values dynamically.
๐ง Advantages of Using SASS
- Makes CSS more powerful and maintainable.
- Reduces code repetition.
- Easy to update and reuse styles.
- Enhances project scalability.
- Fully compatible with standard CSS.
โ๏ธ Difference Between CSS and SASS
Feature | CSS | SASS |
---|---|---|
Full Form | Cascading Style Sheets | Syntactically Awesome Style Sheets |
Type | Stylesheet Language | CSS Preprocessor |
Syntax | Simple | Advanced (SASS or SCSS) |
Variables | Not supported | Supported |
Nesting | Not supported | Supported |
Mixins & Functions | Not supported | Supported |
Compilation | Directly used by browsers | Must be compiled into CSS |
๐งฉ Simple Mixin Example
@mixin button-style($color) {
background-color: $color;
border-radius: 5px;
padding: 10px 20px;
color: white;
}
button {
@include button-style(red);
}
โ
Result:
All buttons will have consistent styling with the specified color.
๐งพ Summary
- SASS = CSS + Programming Features.
- It helps developers write faster, cleaner, and more maintainable styles.
- It is widely used in modern front-end frameworks like React, Angular, and Vue.