Using Variables with SASS Tutorial
An Introduction to Using Variables with SASS

Passionate Software Engineer with three years of experience, dedicated to creating robust and scalable web applications. I have a strong foundation in JavaScript, React, Python, and Node.js, and enjoy working with modern tech stacks to build innovative solutions. I'm committed to writing clean and efficient code, following best practices, and staying updated with the latest industry trends.
Throughout my career, I've gained valuable experience in full-stack development, including frontend design, backend development, and database management. I love solving complex problems and implementing creative solutions that enhance user experiences. I believe in the power of collaboration and thrive in cross-functional teams where I can contribute my skills and learn from others.
Beyond coding, I am an avid learner and enjoy sharing my knowledge with the developer community. I regularly contribute to open-source projects, write technical blog posts, and engage in discussions on emerging technologies. I'm always seeking opportunities to expand my skill set and stay at the forefront of software engineering.
SASS effectively gives us a lot of the programmatic benefits of working with code, only now with the ability to apply it to stylesheets.
Over the next few posts, we’ll be diving right into the features of SASS.
First up let’s introduce variables.
Definition
Variables are a way to store information that you want to reuse throughout your stylesheet.
They allow us to store values for colors, fonts, or really any CSS value that you want to reuse!
We use the $ symbol when we wish to make something a variable.
Example
In our SCSS, let’s define a color variable:
$color-primary: #ffff00; // Yellow
body {
background-color: $color-primary;
}
This will, of course, set our background-color to yellow. It’s that simple!
Note: You can use single-line comments in Sass with //.
When we then run our compile, it’ll output the following CSS:
body {
color: #ffff00;
}
Note: We'll be covering the compilation process further on in this series. For now, it’s good to know that when we save our code into sass/main.scss, it’ll automatically compile into the css/style.css file!
This becomes extremely powerful when working on large projects!
If you wish to make a change to a color used throughout your stylesheets, it’s much simpler to alter if the color is defined in one location as a single variable.
The alternative to changing the value of one variable defined at one location is finding and replacing every reference to the value you want to change. This is a much more tedious task, especially if you want to implement a quick change to test out a different color or font.
Conclusion
If you liked this blog post, follow me on Twitter where I post daily about Tech related things!




