DEV Community

Cover image for What's the difference between Css & Scss
Peter Babatunde
Peter Babatunde

Posted on

What's the difference between Css & Scss

Thank God for style sheet languages like Css and Scss; front-end would have been as stylish as a potato in a tuxedo!
If utilized properly, we can give your users an appealing feeling and a memorable experience with the appearance of our web pages.
The nutshell of this article is this: CSS, primarily, is the powerful **dude that helps us tell our website how it should lookโ€”colors, fonts, spacing, you name it. While Scss is like adding "S*uper" behind the "P*ower" of CSS.
Though, they've got a lot of similarities. Hence, we must clarify the differences.

What are the differences between CSS and Scss?

Cascading Style Sheet or CSS is the standard language used to describe the look and formatting of a document written in HTML. It allows you and me as developers to control layout, colors, fonts, and overall design.

On the other hand, Sassy Cascading Style Sheet or **SCSS **is a superset CSS. What that means is that any valid CSS syntax is also a valid SCSS. But in addition to that, SCSS introduces powerful features like variables, nesting, and mixins, which promote code readability, reusability, and maintainability. But at the end of the day, it's been compiled to CSS behind the scenes since that is what our HTML file can understand.

Think of CSS as customizing your video game character. You get to choose basic features like hair color and clothes. Scss is what helps you take your character up a notch. What if you could save your favorite colors and outfits to reuse again without having to remember every detail? That's the Scss variable feature for you. Note that this is also available with vanilla css.

With Scss, you also get to nest your styling rules. Meanwhile, this cannot be achieved in pure CSS. Nesting lets you keep your code tidy by putting related styles together, making it way easier to read.

Take a look:

Here's Css with which you cannot nest the css rules

.parent{
    padding: 1rem;
}

.child{
    margin: auto;
}
Enter fullscreen mode Exit fullscreen mode

Here's scss allowing you to nest a CSS rule within its parent selector rule block:

.parent{
    padding: 1rem;

    .child{
        margin: auto;
    }
}
Enter fullscreen mode Exit fullscreen mode

Another cool feature that SCSS provides but pure CSS lacks is called "mixins". With SCSS mixins, you can define reusable chunks of CSS, reducing redundancy.
In the video game example I made earlier, Mixins are like keeping both a kneel strike and a punch in a single command. As a result, your character will attack with both moves on an enemy whenever you call that command.
How cool is that? ๐Ÿ˜Š
Instead of having to repeat the same couple of CSS declarations multiple times, You can keep these declarations as a group and apply them altogether by referencing the mixin name.

Take a look:
The typical method of centering a block element with CSS.

.item1{
    display: flex;
    align-items: center;
    justify-content: center;
}

.item2{
    display: flex;
    align-items: center;
    justify-content: center;
}

Enter fullscreen mode Exit fullscreen mode

A better approach with Scss

  1. Create mixin.
@mixin centerItem {
    display: flex;
    align-items: center;
    justify-content: center;
}
Enter fullscreen mode Exit fullscreen mode
  1. Apply (include) mixin where it's needed.

.item1{
@include centerItem;
}

.item2{
@include centerItem;
}

So, while CSS is the basic tool you start with to make your web pages look good, SCSS is like leveling up. It helps you manage everything better, especially when your project gets bigger and more complicated.

Was that helpful?

Top comments (8)

Collapse
 
jonrandy profile image
Jon Randy ๐ŸŽ–๏ธ • Edited

With Scss, you also get to nest your styling rules. Meanwhile, this cannot be achieved in pure CSS

This is not correct, nesting IS available in normal CSS but doesn't quite yet enjoy 100% browser support, but it is very broadly available:
caniuse.com/css-nesting
kilianvalkhof.com/2021/css-html/cs...

Collapse
 
peterbabs profile image
Peter Babatunde

Thanks for the clarity Jon!

Collapse
 
jgdevelopments profile image
Julian Gaston

Hey, good read and highly agree.
One quick thing I wanted to mention, it appears your code blocks are not highlighted. There is a great article that goes over this. Highly recommend.
dev.to/hoverbaum/how-to-add-code-h...

Collapse
 
peterbabs profile image
Peter Babatunde

Thank you, Julian.

This is my first post here on dev.to and I had no idea. So, thanks

Collapse
 
thomasbnt profile image
Thomas Bnt โ˜•

Welcome on DEV @peterbabs, thanks @jgdevelopments for the tips! ๐Ÿ™Œ

Collapse
 
shardz profile image
SHARDZ • Edited

๐ŸŒŸ Thanks for sharing !

Collapse
 
antoracsan profile image
Antonello Constantin

Great and clear article, thank you!

Collapse
 
peterbabs profile image
Peter Babatunde

Thank you for you feedback Antonello. ๐Ÿ‘