Docs
Dark mode

Dark mode

Adding dark mode to your site.

We use the class strategy from Tailwind CSS to support dark mode toggling. See the Tailwind CSS documentation for more information.

How you add the dark class to the html element is up to you. In this guide, we will take a look at enabling dark mode toggling with mode-watcher.

Usage

Install mode-watcher

Start by installing mode-watcher:

	npm install mode-watcher

Add the ModeWatcher component

Import the ModeWatcher component and use it in your root layout:

src/routes/+layout.svelte
	<script lang="ts">
  import { ModeWatcher } from "mode-watcher";
</script>

<ModeWatcher />
<slot />

Add a mode toggle

Place a mode toggle on your site to toggle between light and dark mode.

Light switch

Loading...

Dropdown menu

Loading...