Chapter 4Functions and Mixins

If you are new to Sass, you’ve probably heard that it’s possible to create your own functions, as well as what’s known as mixins. Let’s start with what a function is before moving on to mixins.

Functions

In computer science, a function is a chunk of code that returns a result, possibly accepting arguments. It’s an ideal way to extract repeated pieces of code into a single reusable pattern. As a consequence, functions exist in almost all programming languages, even CSS! Think about it—when writing url(..) or rgba(..), we use CSS functions already. What’s interesting is that Sass not only provides a lot of built-in functions, it also provides authors with a way to define custom functions:

// Using the `darken(..)` ...

Get Jump Start Sass now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.