Add

Lorem ipsum

Lorem ipsum

A
A
A
Design

6 views

6 min

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

Webflow development

From mockup to live website

SEO & GEO

Google visibility and AI search engines

CRO & Growth

Conversion rate optimization

StepActionTool
1Set up CSS variables for colorsWebflow Variables
2Create a dark variant in the variablesWebflow Variables
3Add a toggle buttonWebflow Designer
4Script to switch and remember the modeJavaScript + localStorage

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:

body.dark-mode {
--color-bg: #0f0f0f;
--color-text: #f5f5f5;
--color-surface: #1a1a1a;
}

3. Add a toggle button

Create a button in Webflow and assign it the ID theme-toggle.

4. Add this script in the <body>

const toggle = document.getElementById('theme-toggle');
const saved = localStorage.getItem('theme');
if (saved === 'dark') document.body.classList.add('dark-mode');
toggle.addEventListener('click', function() {
document.body.classList.toggle('dark-mode');
localStorage.setItem('theme',
document.body.classList.contains('dark-mode') ? 'dark' : 'light'
);
});

good to know

To respect the user's system preferences on first load, add this before the script: if (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches) { document.body.classList.add('dark-mode'); }. This automatically turns on dark mode for users who have it enabled in their OS.

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

Good to know

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet consectetur.

Lorem ipsum dolor sit amet consectetur. Aliquam orci sagittis dignissim sapien praesent donec.

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.

Published on

You might be interested in these tutorials

Similar tutorials

SEO / GEO

5 min read

5 views

How to Set Up a Redirect in Webflow? (2026)

Updated on 19.12.2025 by Sandro DA SILVA

SEO / GEO

5 min read

5 views

Add structured data to your Webflow site?

Updated on 21.08.2025 by Sandro DA SILVA

No-code

5 min read

5 views

How to Obfuscate a Link in Webflow

Updated on 23.04.2025 by Sandro DA SILVA

Let’s f*****G GO !!

Ready to launch
Your business?

Alexandre

Max

Enora

Bryan

Cannelle

Tiphaine

You'll :heart: our collaboration...