We can use SASS in many situations, including:
- An online environment that automatically converts code from SASS to CSS
- A package in our system, such as the Surge from the first project
- A separate program that converts files from SASS or SCSS to CSS format
Let us deal with each point separately. During the course, you can use any option you are comfortable with. When you work with real projects, you should install SASS as a package on your system. Then you can use assemblers and automate compilation — conversion of a SASS code to CSS.
Online environment
If you want to use SASS in an online environment, almost any online code editor you know will work. For example, you can use CodePen. In the CSS tab, you can tell it to use the SASS preprocessor. For the SCSS syntax, you need to select the appropriate drop-down menu item:
It is the easiest and fastest option for writing CSS code using the SASS preprocessor.
Another popular tool is the Sassmeister, which quickly translates SASS code into plain CSS. The advantage of this service is the ability to select different types of compilers. It allows you to test your code under various conditions and possibly identify a few bugs you may encounter.
Software
You can install separate software that compiles preprocessor files into CSS files. There are many such programs, and many of them are available for all major platforms (Windows, Linux, macOS). One polular program is Koala. Its intuitive interface allows you to understand the process and easily compile preprocessor files.
Just select the directory with your SCSS file, and Koala will automatically convert them to a CSS file:
Installing SASS as a package
You can install SCSS as an NPM package on your system. It is the easiest and fastest way to use SASS without installing additional software. And it does not require an Internet connection, as is the case with online services.
When installing SASS, make sure you have Node.js installed. Open the terminal and run the following command:
sudo npm install -g sass
After installing Chocolatey, run the following command:
choco install sass
Use the following command to install SASS on macOS:
brew install sass/sass/sass
After installing the package, the SASS command will be available to you in the terminal:
sass /project/src/style/style.scss /project/build/style/style.css
In its basic form, you only need to pass it two parameters:
- The path to the input file. It is the SASS or SCSS file on your system
- The path to the output file. Here, you can specify the path to the CSS file, where all CSS will be after compilation. You do not have to create this file beforehand. If it does not exist, the program will create it in the path you specified
In addition to the compilation, you also can run an interactive — Shell. With it, you can easily experiment with different SASS functions. To start the interactive shell, run the sass -i
command in the terminal:
sass -i
>> 1px + 1px
2px
As you go through the course, you will encounter different features. Try them in the interactive shell.
All examples and exercises in this course will be compiled using this library. The library is called Dart-SASS. Different compilers can handle SASS code differently. The differences are insignificant, but identifying the differences when choosing a library is worth trying.
Additional materials
- SASS installation documentation
Additional assignment
Install SASS on your computer using a batch manager. Try creating a file with an SCSS extension and compiling it. You can enter the following code in the SCSS file:
header {
width: 50%;
background: brown;
&.w-100 {
width: 100%;
}
}
See what you get in the CSS file after compilation.
Are there any more questions? Ask them in the Discussion section.
The Hexlet support team or other students will answer you.
For full access to the course you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.