How to Use Sass to Build One Project With Multiple Themes

The frontend-developer’s workflow has undergone big changes in recent years. More complexity, higher requirements and bigger projects move us toward new technologies such as preprocessors. Personally, I love my preprocessor workflow and wouldn’t want to miss Sass for my projects these days – without it I would be a mess.

One situation in particular where Sass has helped me out is in creating a single solid frontend which can have different themes – changing colors, images or the fonts with ease. Today I’m going to describe my workflow, I hope you take something useful away from it.

Basic Structure

Here is the structure of an example project. You can use whatever partials you logically feel should be included. The key is in having a separate folder for themes and a new .scss file for each theme. 


|- _scss/
|-|- _base/
|-|-|- _config.scss
|-|- _layouts/
|-|-|- _l-grid.scss
|-|-|- _l-default.scss
|-|- _modules/
|-|-|- _m-accordions.scss
|-|-|- _m-teasers.scss
|-|-|- _light-theme/
|-|-|-|- light.scss
|-|- application.scss

Build the Base with a Main File

In the application.scss file you import all your partials, ignoring the folder _themes/ at this point. This builds the foundation upon which we can create different themes.

@charset 'UTF-8';
// 1.Base
@import '_base/_config.scss';
// 2.Layouts
@import '_layouts/_l-grid',
// 3.Modules
@import '_modules/_m-accordions',


Colors, Fonts and much more

Configuring your project is very important. Here variables come to the rescue, allowing us to set defaults then overwrite values at the theme level later on. Here you can see I’ve set some variables for colors, fonts and border settings.

For more detail on naming variables take a look at Jim Nielsen’s Quick Tip: Name Your SASS Variables Modularly.

@charset "UTF-8";
// Colors
$black: #000;
$white: #fff;
$red: #e2061c;
$gray-light: #c9c8c8;
$gray: #838282;
$gray-dark: #333333;
$blue: #253652;
// Corp-Colors
$corp-color: $blue !default;
$corp-color-dark: darken($corp-color, 15%) !default;
$corp-color-second: $red !default;
$corp-color-second-dark: darken($corp-color-second, 15%) !default;
// Font
$base-font-size: 1.8 !default;
$base-font-family: Helvetica, Arial, Sans-Serif !default;
$base-font-color: $gray-dark !default;
// Border
$base-border-radius: 2px !default;
$rounded-border-radius: 50% !default;
$base-border-color: $gray !default;

The key to this stage is in using the !default flag after the variable declarations. Doing this allows you to overwrite them within the theme .scss files; the !default effectively says “use this value if it isn’t defined elsewhere”.


Very often developers don’t create variables for images, instead writing urls directly within selectors. An approach I like is to remove all paths within partials and put them in the configuration file as variables. This will make your life easier and the project better maintainable.

// Images
$sprite:              '../images/base/sprite.png' !default;
$colorbox-background: '../images/base/colorbox-background.png' !default;

Example of a Basic Module

Here you can see some background variables in action. This is a modular partial for an accordion, making use of the global variable $sprite but also setting and using a variable $accordion-bgcolor which is specific to the module. 

// 1.Config
$accordion-bgcolor: $gray !default;
// 2.Base
.m-accordion {
padding: 20px;
background: $accordion-bgcolor;
.m-accordion__trigger {
background: url($sprite) no-repeat;

How to Create a Theme

In your theme file (such as the _themes/_light-theme/light.scss from the demo structure above) import the application.scss which contains all the modules, layouts and so on. This is the basis for everything; with a theme we’ll be placing a second layer over it. Nothing more. Once you’ve imported application.scss add the same variables used earlier, but define values specific to this theme. 

Using this technique, if we add new modules to the base of the project we will automatically (and harmlessly) compile them within all our themes.

@charset 'UTF-8';
// 1.Overwrite stuff
$corp-color: $gray;
$corp-color-darken: darken($corp-color, 10%);
$corp-color-second: $blue;
$corp-color-second-dark: darken($corp-color-second, 10%);
$base-font-size: 1.6;
$base-font-family: Droid Sans, Georgia, Arial;
$base-border-radius: 0px;
$base-border-color: $gray-light;
// Images
$sprite:              '../images/light/sprite.png';
$colorbox-background: '../images/light/colorbox-background.png';
$accordion-bgcolor: $gray-light;
// 2. Import basic theme
@import '../../application';

Watching Multiple Files in Sass

The last step is to compile the Sass to CSS and get two different files for usage. We must compile application.scss and the light.scss. Using the command line you’d use something like:

sass --watch 

If you use an app, such as CodeKit, or Prepros App, compiling will be a more visual process.

Include the light.css file in the head of your page and take a look at your freshened up website.


As you can see, it’s helpful and straightforward to have multiple theme files, all based upon one solid foundation. Feel free to ask questions, or give feedback and share your experiences with us in the comments section.