How to create a theme switcher with HTML & CSS

A few custom properties and the :has() selector make color theming super easy to do! Add in a bit of JS and we can save the user’s preferences in localStorage, and we’re good to go! Of course, :has() support isn’t perfect, but we can build in a quick fallback with just a little bit more JS. 🔗 Links ✅ The code from this video: ✅ More on visually-hidden: ✅ Current support for :has() - ⌚ Timestamps 00:00 - Introduction 00:57 - What we’re starting with 01:58 - Setting up the color theme selector 04:04 - Hiding the labels 05:39 - Styling the color theme picker 12:05 - Adding functionality with :has() 13:48 - Using localStorage to remember the users choice 23:52 - Adding a fallback for when there is no :has() support Corrections: 24:54 I should have made separate se
Back to Top