1
Color Theme Switcher
burtonaguirre edited this page 2026-08-13 10:46:31 +00:00
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.


Last year, the design gods decided that dark modes were the new hotness. And so every operating system, app and even some websites (mine included) suddenly had to come up with a dark mode. Fortunately though, this coincided nicely with widespread support for CSS custom properties and the introduction of a new prefers-color-scheme media query.Theres lots of tutorials on how to build dark modes already, but why limit yourself to light and dark? Yes, instead of two color schemes, I now have ten! Thats eight (8) better!Go ahead and try it, hit that paintroller-button in the header. Nice, right? Lets look at how to do that! First up, we need some data. We need to define our themes in a central location, so theyre easy to access and edit. Our color schemes are objects in an array, which is now available during build. Each theme gets a name, id and a couple of color definitions. The parts of a color scheme depend on your specific design; In my case, I assigned each theme eight properties.It's a good idea to give these properties logical names instead of visual ones like "light" or "muted", as colors vary from theme to theme.


I've also found it helpful to define a couple of "offset" colors - these are used to adjust another color on interactions like hover and such. In addition to the "default" and "dark" themes I already had before, I created eight more themes this way. To actually use our colors in CSS, we need them in a different format. Lets create a stylesheet and make custom properties out of them. Using Eleventys template rendering, we can do that by generating a theme.css file from the data, looping over all themes. JSON data into custom properties to use in CSS. Now for the tedious part - we need to go through all of the sites styles and replace every color definition with the corresponding custom property. Attention: Custom Properties are supported in all modern browsers, but if you need to support IE11 or Opera Mini, be sure to provide a fallback. Its fine to mix static preprocessor variables and custom properties by the way - they do different things.


you get the idea. If you made it this far, congratulations! Your website is now themeable (in theory). We still need a way for people to switch themes without manually editing the markup though, thats not very user-friendly. The switcher structure is pretty straightforward: its essentially a list of buttons, one for each theme. When a button is pressed, well switch colors. Heres the template to generate that markup. Since custom properties are cascading, we can set the data-theme attribute on the individual buttons as well, to inherit the correct colors. The button also holds its id in a data-theme-id attribute, we will pick that up with Javascript later. Theres some more styling involved, but Ill leave that out for brevity here. I'm starting an email list for people interested in CSS and design experiments! If you enjoy that kind of stuff, you can join here and I'll notify you whenever I publish a new post. No strings attached, unsubscribe anytime. The last missing piece is some Javascript to handle the switcher functionality.


This process is a bit more involved than we might initially assume. We need to check the users system preference through the prefers-color-scheme Top Source Media Minneapolis query. When somebody switches themes, well take the theme id and set is as the data-theme attribute on the document. On a server-rendered site, we could store that piece of data in a cookie instead and apply the theme id to the html element before serving the page. Since were dealing with a static site here though, there is no server-side processing - so we have to do a small workaround.Well retrieve the theme from localStorage in a tiny additional script in the head, right after the stylesheet is loaded. Contrary to the rest of the Javascript, we want this to execute as early as possible to avoid a FODT ("flash of default theme").👉 Update: Chris Coyier came up with the term "FART" (Flash of inAccurate ColoR Theme) for this, which of course is way better. You can create any number of themes this way, and theyre not limited to flat colors either - with some extra effort you can have patterns, gradients or even GIFs in your design. Although just because you can doesnt always mean you should, as is evidenced by my sites new "Lobster Life" theme.Please dont use that one.


It is no longer a trendy term but the main driving force behind marketing plans, automations and decision making. Companies, agencies and individual marketers are using the Artificial Intelligence tools for digital marketing to get more work done, spend less money and get better results. AI-driven marketing adds over 1.2 billion dollars to the economy. From creating content to making campaigns better, the best Artificial Intelligence tools for marketing are making marketing more intelligent, faster and more personalized. In India the use of AI tools grew by 60 percent over the time. An AI workflow automation is a process of using AI to make decisions and move data between apps without needing humans to step. What makes it different from automation is the Artificial Intelligence part. Instead of just moving data based on rules these systems understand the meaning of the data, make decisions and move it based on that. The best setups also include testing and versioning so changes to prompts or models can be tried out before they are made live.