As a new WordPress theme
designer, you would quickly learn the challenges of maintaining long CSS files while keeping them
organized, scalable, and readable. You will also learn that many designers and
front-end developers recommend using a CSS preprocessor language like Sass or
LESS. But what are these things? and how do you get started with them? This
article is an introduction to Sass for new WordPress Theme Designers. We will
tell you what a CSS preprocessor is, why you need it, and how to install and
start using them right away.
What is Sass?
The CSS that we use was
designed to be an easy to use stylesheet language. However web has evolved, and
so is the need of designers to have a stylesheet language that allows them to
do more with less effort and time. CSS preprocessor languages, like Sass, allow
you to use features that are not currently available in the CSS such as using
variables, basic math operators, nesting, mixins, etc.
Getting Started With Sass
for WordPress Theme Development
Most theme
designers use local development environment to work on their themes before
deploying it to a staging environment or a live server. Since Sass is a
preprocessor language, you will need to install it on your local development
environment.
First thing you need
to do is to install Sass. It can be used as a command line tool, but there are
also some nice GUI Apps available for Sass. We recommend usingKoala, which is a free opensource app
available for Mac, Windows, and Linux.
For the sake of
this article, you will need to create a blank theme. Simply create a new folder
in /wp-content/themes/. You can name it ‘mytheme’ or anything
else you want. Inside your blank theme folder create another folder and name it
stylesheets.
In the
stylesheets folder, you need to create a style.scss file using a text editor like Notepad.
Now you need to
open Koala and click on the plus icon to add a new project. Next, locate your
theme directory and add it as your project. You will notice that Koala will
automatically find the Sass file in your stylesheets directory and display it.
Right click on your Sass
file and select Set Output Path option.
Now select the root of your theme directory, example, /wp-content/themes/mytheme/ and hit enter. Koala
will now generate CSS output file in your theme directory. To test this you
need to open your Sass file style.scss in a text editor like
Notepad and add this code:
What about CSS @import?
The problem with
using @import in your CSS file is that each time you add an @import, your CSS
file makes another HTTP request to the server. This effects your page load time
which is not good for your project. On the other hand, when you use @import in
Sass, it will include the files in your Sass file and serve them all in a
single CSS file for the browsers.
To learn how to
use @import in Sass, first you need to create a reset.scss file in your theme’s stylesheets
directory and paste this code in it.
As a new WordPress theme
designer, you would quickly learn the challenges of maintaining long CSS files while keeping them
organized, scalable, and readable. You will also learn that many designers and
front-end developers recommend using a CSS preprocessor language like Sass or
LESS. But what are these things? and how do you get started with them? This
article is an introduction to Sass for new WordPress Theme Designers. We will
tell you what a CSS preprocessor is, why you need it, and how to install and
start using them right away.
What is Sass?
The CSS that we use was
designed to be an easy to use stylesheet language. However web has evolved, and
so is the need of designers to have a stylesheet language that allows them to
do more with less effort and time. CSS preprocessor languages, like Sass, allow
you to use features that are not currently available in the CSS such as using
variables, basic math operators, nesting, mixins, etc.
Getting Started With Sass
for WordPress Theme Development
Most theme
designers use local development environment to work on their themes before
deploying it to a staging environment or a live server. Since Sass is a
preprocessor language, you will need to install it on your local development
environment.
First thing you need
to do is to install Sass. It can be used as a command line tool, but there are
also some nice GUI Apps available for Sass. We recommend usingKoala, which is a free opensource app
available for Mac, Windows, and Linux.
For the sake of
this article, you will need to create a blank theme. Simply create a new folder
in /wp-content/themes/. You can name it ‘mytheme’ or anything
else you want. Inside your blank theme folder create another folder and name it
stylesheets.
In the
stylesheets folder, you need to create a style.scss file using a text editor like Notepad.
Now you need to
open Koala and click on the plus icon to add a new project. Next, locate your
theme directory and add it as your project. You will notice that Koala will
automatically find the Sass file in your stylesheets directory and display it.
Right click on your Sass
file and select Set Output Path option.
Now select the root of your theme directory, example, /wp-content/themes/mytheme/ and hit enter. Koala
will now generate CSS output file in your theme directory. To test this you
need to open your Sass file style.scss in a text editor like
Notepad and add this code:
What about CSS @import?
The problem with
using @import in your CSS file is that each time you add an @import, your CSS
file makes another HTTP request to the server. This effects your page load time
which is not good for your project. On the other hand, when you use @import in
Sass, it will include the files in your Sass file and serve them all in a
single CSS file for the browsers.
To learn how to
use @import in Sass, first you need to create a reset.scss file in your theme’s stylesheets
directory and paste this code in it.