Introduction
SASS (Syntactically Awesome Stylesheets) is a CSS preprocessor that adds powerful features like variables, nesting, mixins, and functions, making stylesheets more maintainable and efficient.
1. What is SASS/SCSS?
SASS comes in two syntaxes:
- SASS (Indented Syntax): Uses indentation instead of braces.
- SCSS (Sassy CSS): Similar to CSS but with additional features.
Example SCSS:
$primary-color: #3498db;
body {
background-color: $primary-color;
}
CSS2. Installing SASS
Use Node.js and npm:
npm install -g sass
BashCompile SCSS to CSS:
sass style.scss style.css
Bash3. Features of SASS/SCSS
Variables
$font-size: 16px;
p {
font-size: $font-size;
}
CSSNesting
nav {
ul {
list-style: none;
}
}
CSSMixins (Reusable Styles)
@mixin button-style {
background: blue;
color: white;
padding: 10px;
}
button {
@include button-style;
}
CSSFunctions
@function double($value) {
@return $value * 2;
}
div {
width: double(10px);
}
CSSImporting Files
@import 'buttons'
CSS4. Advantages of SASS
- Modular and reusable code
- Faster development
- Better organization
Conclusion
SASS/SCSS enhances CSS with advanced features, making stylesheets more efficient and scalable.