Docs
Dark mode

Dark mode

Adding dark mode to your Svelte 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 i 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";
  let { children } = $props();
</script>
 
<ModeWatcher />
{@render children?.()}

Add a mode toggle

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

Light switch