CSS is a cornerstone of modern web design – it’s the style sheet language that makes the web more than just a collection of boring text documents. But it has its limits.
For designers who need to get maximum functionality from CSS, preprocessors are the ideal tools. CSS preprocessors like Sass help to create CSS code that’s more efficient and easier to maintain – and for more complex web projects, this can be an essential requirement.
Back to basics: what is CSS and why do we need it?
Before exploring the world of preprocessors, it’s important to have a firm grasp of the CSS fundamentals.
Short for Cascading Style Sheets, CSS is a language that sets the presentation and style of documents written in a markup language such as HTML. CSS is also compatible with XHTML, plain XML, SVG and XUL, but it’s most commonly used to describe how HTML elements should be displayed on webpages.
The classic metaphor for the relationship between CSS and HTML is the human body. If HTML is the skeleton – the core content and page structure – then CSS is the skin – the visual component layered on top. Without CSS, web browsers would just render HTML as plain text, without the colours, fonts, layouts and images that define the web as we know it.
This hints at a key principle surrounding the use of CSS: the separation of the page’s presentation from its content.
With the ability to apply a single style sheet to multiple pages and get consistent results, CSS enables a modular approach to visual elements, helping designers reduce complexity and save time. This can greatly simplify design tasks that often involve several developers working across various web formats.
All this makes CSS an essential component of web design, but also raises the question: if regular CSS is so great, why use a preprocessor?
What CSS preprocessors add
CSS preprocessors are essentially new scripting languages that offer a variety of features not available with standard CSS. After being written, the preprocessor script is compiled into regular CSS code to render pages as normal.
A preprocessor can’t fundamentally change the capabilities of CSS – the script has to be converted to CSS, after all – but it does make it easier to squeeze more functionality from regular Cascading Style Sheets. Code can be made cleaner and more manageable, with lots of features that help developers produce better quality CSS, faster.
With that said, preprocessors aren’t recommended for CSS beginners, since it’s more important to understand the basics of the language when starting out. While a preprocessor makes advanced CSS easier to manage, it also adds an additional step in the development process, potentially allowing more room for error.
What is Sass?
Sass (Syntactically Awesome Style Sheets) is one of the most popular CSS preprocessors currently available. The actual language used by Sass is called SassScript – this is what developers write in before compiling their code as CSS.
There are technically two Sass syntaxes: Sass and SCSS (Sassy CSS). The older Sass syntax uses the .sass file extension and is less similar to CSS, with more focus on concise code. The newer SCSS can be recognised by the .scss extension, and is closer to CSS standards.
Sass is totally backward compatible with CSS, so all existing CSS files can easily be converted to Sass. But Sass also offers a range of new features including variables, which are sets of values that are simple to store and reuse. For example, Sass variables can be used to set specific hexadecimal colours, avoiding the need to go back and find the right code every time.
Mixins are another Sass feature that helps developers reuse blocks of code throughout a site – essentially creating a template for complex CSS. Other features of Sass that help to organise code include loops, nesting, inheritances and partials.
Taken as a complete package then, Sass is very much focused on helping developers create more advanced CSS, and equally importantly, making that CSS simple to manage and maintain. Sass, and CSS preprocessors in general, should be seen in the context of “don’t repeat yourself” – the long-established software engineering principle that advocates lean, efficient code with minimal repetition and reuse wherever possible.
Whether you’re just getting started with CSS or building complex sites with a preprocessor like Sass, you’ll need a reliable hosting platform. At Fasthosts we provide advanced , powerful and next-gen , all with the performance and security of UK data centres. Get in touch for more details on our full range of solutions for web designers and developers.