← Back to CSS
66

Sass: variables, nesting and mixins

Use Sass as a practical layer on top of CSS to organize design tokens, control nesting and reuse recurring patterns with mixins, while still compiling to clean output the team can review.

📘 Theory

Variables as design tokens

1

Sass variables are a convenient way to centralize repeated values such as brand colors, radii and spacing scales.

2

In real projects, they often act as authoring tokens that feed components consistently before the final CSS is compiled.

Nesting with discipline

A little nesting improves readability. Too much nesting creates selector traps.

1

Nesting works best when it mirrors a small component structure, such as a block, its element and one or two states.

2

If the compiled selector becomes hard to read or too specific, the nesting has gone too far.

Reusable mixins

1

A mixin bundles a repeated styling pattern so you do not have to copy the same cluster of declarations across components.

2

They are especially useful for recurring structures such as buttons, responsive breakpoints, focus rings or theme variants.

🧪 Learn by doing

Example Example: brand variables Use Sass variables to define a small brand palette and spacing rule once, then consume them inside the component.

🏁 Challenges

Challenge Challenge: complete the mixin Finish a base button mixin by adding the two structural properties the component still needs.

🧰 Resources

Useful links

Test

Check your knowledge with a test about CSS.

Test for CSS

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com