Have you ever visited a website and been immediately drawn to how it looks? Before you even read a word, the colors, layout, and overall visual appeal make a first impression.
As web designers, we have quite a few options for styling these elements. Let's dive into two popular choices - CSS and its more powerful cousin, SCSS - and see how they stack up against each other.
What is CSS?
CSS (Cascading Style Sheets) is the standard styling language for webpages. Along with HTML and JavaScript, it's one of the three core technologies that power the web.
Think of CSS as the language that tells browsers how to present your content - what colors to use, which fonts to display, how big elements should be, and so on.
Here's a simple example of CSS:
body {
color: #6fda44;
font-family: Neuemontreal, sans-serif;
font-size: 16px;
}
This code tells the browser to make all text in the body green (#6fda44), use the Neuemontreal font (or any sans-serif font if that one isn't available), and set the font size to 16 pixels.
What is SCSS?
SCSS stands for Sassy CSS - yes, really! It's part of Sass (Syntactically Awesome Style Sheets), which is a CSS preprocessor.
The key thing to know is that SCSS is a superset of CSS, meaning any valid CSS code will work as SCSS. Files using this syntax get saved with a .scss extension.
Here's what the same styling looks like in SCSS:
$green: #6fda44;
body {
color: $green;
font-family: Neuemontreal, sans-serif;
font-size: 16px;
}
Notice that we can create a variable ($green) to store our color value? That's just one of the cool features SCSS gives us.
By the way, Sass also has an older syntax that uses indentation instead of curly braces (saved with a .sass extension), but most developers prefer SCSS because it's compatible with regular CSS.
Main differences between SCSS and CSS
CSS is great, but it can get repetitive when working on bigger projects. Imagine having to type the same colors and font styles over and over again throughout your stylesheets.
Let's compare how both handle the same styling:
In CSS:
body {
background: #6fda44;
color: #ffffff;
}
.navbar {
font: Neuemontreal, sans-serif;
color: #ffffff;
font-weight: 600;
}
Now in SCSS:
$background-color: #6fda44;
$text-color: #ffffff;
$neufont: Neuemontreal, sans-serif;
$font-weights: (
"regular": 300,
"bold": 600,
"large": 800
);
body {
background: $background-color;
color: $text-color;
}
.navbar {
font: $neufont;
color: $text-color;
font-weight: map-get($font-weights, bold);
}
See the difference? With SCSS, we define our styles once at the top and use them throughout the code. Even better, we can create data structures like the $font-weights map and pull values as needed.
Advanced features of SCSS
SCSS also lets us use functions and mixins, which are like reusable blocks of styling code:
/* A function that calculates values */
@function pow($base, $exponent) {
$result: 1;
@for $_ from 1 through $exponent {
$result: $result * $base;
}
@return $result;
}
.sidebar {
float: left;
margin-left: pow(4, 3) * 1px;
}
/* A mixin for reusing style combinations */
@mixin rtl($property, $ltr-value, $rtl-value) {
#{$property}: $ltr-value;
[dir=rtl] & {
#{$property}: $rtl-value;
}
}
.sidebar {
@include rtl(float, left, right);
}
This advanced stuff makes it way easier to maintain and update your styles. Change a variable once, and it updates everywhere you've used it. No more hunting through your CSS to change every instance of a color!
How to get started with SCSS
Ready to try SCSS? You'll need to install Sass first. Here are some ways to do it:
Use an IDE extension - The easiest way is adding a compiler extension to your code editor. For example, VS Code has the Live Sass Compiler extension that automatically converts your SCSS files to CSS when you save.
Try a development app - Tools like CodeKit (for Mac) and LiveReload already include Sass capabilities.
Install via NPM - If you're comfortable with the command line, you can use Node Package Manager:
npm install -g sass
Use package managers - On Windows with Chocolatey:
choco install sass
Or on Mac/Linux with Homebrew:
brew install sass/sass/sass
You can learn more about installation options on the official Sass website.
Conclusion
SCSS takes everything good about CSS and makes it even better. With variables, mixins, functions, and nested styles, SCSS helps developers write more organized, maintainable, and DRY (Don't Repeat Yourself) code. While regular CSS works perfectly fine for smaller projects, SCSS truly shines when you're working on larger websites or applications where style consistency is crucial. The initial setup might take a few minutes, but the time you'll save down the road makes it well worth the effort. If you're looking to level up your front-end development skills, learning SCSS is definitely a smart move!