Menu

Sass Explained: CSS With Variables, Nesting, and Logic
πŸ“°

Sass Explained: CSS With Variables, Nesting, and Logic

DEV Community: sassΒ·The Practical DeveloperΒ·1 day ago
#iGMiokLg
#devtosass#devto#dev#variables#sass
Reading 0:00
15s threshold

Introduction

CSS (covered twice already) works, but it repeats itself: the same colour value in twenty places, the same media query copied again and again, no variables, no reuse. Sass, created by Hampton Catlin in 2006, is a preprocessor β€” a language that adds programming features to CSS and then compiles down to plain CSS the browser understands. Its SCSS syntax (the standard today) looks like CSS with superpowers, which is why it spread through large codebases long before CSS itself gained variables.

Variables, nesting, and mixins

Three features explain most of Sass's appeal:

$primary : #2563eb ; $spacing : 16px ; .card { padding : $spacing ; border : 1px solid $primary ; h2 { color : $primary ; margin-bottom : $spacing ; } & :hover { border-color : darken ( $primary , 10% ); } } @mixin center { display : flex ; align-items : center ; justify-content : center ; } .hero { @include center ; }

Enter fullscreen mode

Exit fullscreen mode

Variables ( $primary ) mean a colour changes in one place, not…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.