How to Create Dark Mode in Webflow
Learn how to create a dark mode in Webflow with CSS variables, a toggle button, and localStorage to remember the user’s choice.
In this tutorial, Sandro, cofounder of Gemeos Webflow agency, shows you how to create a dark mode in Webflow using CSS variables and localStorage.
Example
1. Define your CSS variables in Webflow
In the Designer, go to Variables. Create color variables: --color-bg, --color-text, --color-surface. Assign these variables to all your elements (backgrounds, text, borders) instead of using direct colors.
2. Create the "dark-mode" class on the body
Add a CSS embed with the dark values for your variables:
3. Add a toggle button
Create a button in Webflow and assign it the ID theme-toggle.
4. Add this script in the <body>
Conclusion
Dark mode improves reading comfort and matches modern user preferences. Use cases:
- Documentation sites or technical blogs
- SaaS tools and dashboards
- Creative websites with a strong visual identity
Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.















