DEV Community

Discussion on: Dynamic CSS in Svelte

Collapse
 
csaltos profile image
Carlos Saltos

Interesting hack !! ... but what about using an Svelte preprocessor with SCSS !! ... that will have also variables ... and also mixins, imports, extends and other cool stuff and for using with Svelte ... check it out -> github.com/sveltejs/svelte-preprocess

Collapse
 
dimfeld profile image
Daniel Imfeld • Edited

Yeah, I use PostCSS for those purposes along with Tailwind CSS. Definitely makes things more convenient when you can define things in one place and use them throughout the application.

CSS Variables like I described in this article are most useful when you can't predict the values needed at build time. I have a couple examples of this embedded in the page on the version of this post on my actual website or you can also check it out on this Svelte REPL example.

Here's another cool example not by me, where CSS variables are used to selectively change the style on certain elements of a design: lea.verou.me/2020/07/the-cicada-pr...

Thanks for reading!