DEV Community

Cover image for How to use CSS variables to create amazing theme transitions 🎨✨

How to use CSS variables to create amazing theme transitions 🎨✨

Cătălin Onuțu on November 13, 2023

CSS variables They are a great out-of-the-box tool that enables you to write cleaner and more reusable styles. Similar to how variables...
Collapse
 
davboy profile image
Daithi O’Baoill

Excellent, thanks

Collapse
 
wraith profile image
Jake Lundberg

nice article 😀 variables really have made this sort of thing way easier!

as you’ve shown here, it’s good practice to use the system settings as your default, but you also want the user selection to override that so they can have more granular control over their experience.

this subject also goes way deeper as you start to introduce selection persistence, SSR, and custom themes that go beyond just light and dark. maybe a follow up post??? 😉

again, nice aricle! and keep up the great work!

Collapse
 
cataon profile image
Cătălin Onuțu • Edited

selection persistence, SSR, and custom themes that go beyond just light and dark

Indeed, it becomes a bit more interesting when it comes to synchronizing default & opt-in preferences -- then persistence. 😁

I probably will come up with a follow-up post on these.
Thanks for the feedback and for this great suggestion!

Collapse
 
derick1530 profile image
Derick Zihalirwa

i can't wait to read it

Collapse
 
francescovetere profile image
Francesco Vetere

Very nice article! Thanks ☺️

Collapse
 
cataon profile image
Cătălin Onuțu

Thank you!
Since this is my first post, your comment motivates me to continue 😁

Collapse
 
francescovetere profile image
Francesco Vetere

Glad to hear that! 💪

Collapse
 
dsaga profile image
Dusan Petkovic

Thanks for the article, do you know if this "prefers-color-scheme" is configured in the browser settings somewhere? I remember that there was an attribute that can be added to the body tag or something to indicate which color scheme a user prefers...

Collapse
 
cataon profile image
Cătălin Onuțu

I believe it is an operating system level setting and the browser passes it onto loaded pages. That is happening on the combination of macOS & Chrome that I'm using. It could differ on other operating systems though.
my macOS theme settings

By the sounds of it, you might be referring to the color-scheme property.