DEV Community

Avinash Kumar
Avinash Kumar

Posted on

CSS vs SASS!

When it comes to styling web pages, there are a few different options to choose from. One of the most popular is CSS (Cascading Style Sheets), but another option that's gained traction in recent years is SASS (Syntactically Awesome Style Sheets). In this post, we'll take a closer look at the differences between these two styling options and help you decide which one might be the best fit for your next project.

First, let's talk about CSS. CSS is a stylesheet language used for describing the presentation of a document written in a markup language, like HTML. It's used to apply styles such as colors, fonts, and layouts to web pages. CSS is a widely-used and well-supported option, and it's the standard for styling web pages. It's simple to learn, and there are a wide variety of resources available online to help you get started.

While CSS is a great option, it can become cumbersome as the size and complexity of your project increases. This is where SASS comes in. SASS is a preprocessor for CSS that adds features such as variables, nested rules, and mixins (reusable blocks of styles). These additional features make SASS a more efficient and organized option for styling large and complex projects.

One of the biggest advantages of SASS is its use of variables. With CSS, if you want to use the same color or font throughout your website, you'll need to use the same value repeatedly. With SASS, you can define a variable for that value and use it throughout your stylesheet, making it much easier to make global changes.

Another advantage of SASS is its use of nested rules. In CSS, you need to repeat the parent element for each child element you want to style. With SASS, you can nest child elements within their parent elements, making your stylesheet more readable and easier to maintain.

Mixins are another powerful feature of SASS. They allow you to define a block of styles that can be reused throughout your stylesheet. This can save you a lot of time and effort when you need to apply the same styles to multiple elements.

Once you've written your SASS code, it needs to be compiled into standard CSS before it can be applied to your web page. This might sound like an extra step, but it's actually quite simple to set up, and there are many tools available that make the process even easier.

In summary, CSS is a popular and well-supported option for styling web pages. It's simple to learn and use, but it can become cumbersome for large and complex projects. SASS is a preprocessor for CSS that adds features such as variables, nested rules, and mixins, making it a more efficient and organized option for styling large and complex projects. Ultimately, the choice between CSS and SASS will depend on the size and complexity of your project, as well as your personal preferences.

Top comments (6)

Collapse
 
imluka profile image
Luka Dušak

I would note that it is absolutely possible to use variables in vanilla CSS.
It would look something like this:

:root {
  --color-light: #f7f7f7;
  --background-dark: #01031a;
}
Enter fullscreen mode Exit fullscreen mode

At the root of the CSS file variables are defined.
We can use variables in classes without a problem:

.some-class {
  background-color: var(--background-dark);
  color: var(--color-light);
}

.another-class {
  color: var(--color-light);
}
Enter fullscreen mode Exit fullscreen mode

By changing a variable in one place, the changes will be visible in all class instances that use that variable.

Collapse
 
darkxenium profile image
Avinash Kumar

Well you are right but there is a small difference in their respective variables. In Sass variables are imperative, which means if you use a variable and then change its value, the earlier use will stay the same whereas, CSS variables are declarative, i.e if you change the value, it'll affect both earlier uses and later uses.

Collapse
 
chabulsqu profile image
Chabulsqu

Great article! I began learning Sass when I started using the framework Bootstrap as I wanted to add customs styles for it and it's really very convenient. However, CSS already has variables built-in, they are not as powerful as the Sass one but they can be used the same way.
For now I use Bootstrap for smaller projects, Sass + Bootstrap for larger ones and CSS if I want to suffer (just kidding)

Collapse
 
darkxenium profile image
Avinash Kumar

Yes, I do something similar as well for smaller and larger projects.

Collapse
 
julimuz profile image
Julian Muñoz

Great post! actually I'm learning sass, It's really amazing, some recomendations for the learning path?

Collapse
 
darkxenium profile image
Avinash Kumar

Sure, I love NetNinja's youtube videos. The link - youtube.com/playlist?list=PL4cUxeG... You can follow this and later try building your own projects.