Sass Variables vs CSS Custom Properties
People think Sass variables and CSS custom properties are the same thing, and they are not. A Sass variable, like $brand, is used up when the Sass turns into CSS, so the browser never sees it. A custom property, like --brand, lives in the browser. Code can change it while the page runs, which is how dark mode can work.
Sass
A language for writing CSS with extra tools, like nesting. It turns into plain CSS.
Sass is a language that adds extra tools to CSS, then turns into plain CSS for the browser. It lets you nest rules, share pieces of style, and split your styles into many files. Most people write it in .scss files, where any normal CSS still works. A tool called a compiler turns those files into one .css file. Browsers never see the Sass itself.
CSS Custom Properties
Named values in CSS, like --brand, that you set once and reuse all over the page.
CSS custom properties are values you name once and reuse across a stylesheet. The name starts with two dashes, like --brand. You read it back with var(--brand), and you can give a backup value after a comma. Most people set them on :root, so the whole page can use them. Change one line, and every place that uses it changes too.
In one line
- Sass
- A language for writing CSS with extra tools, like nesting. It turns into plain CSS.
- CSS Custom Properties
- Named values in CSS, like --brand, that you set once and reuse all over the page.