SSR-friendly light and dark mode for SvelteKit
npm install mode-watcherSimple utilities to manage light & dark mode in your SvelteKit app.




``bash`
npm install mode-watcher
Add the ModeWatcher component to your root +layout.svelte file.
`svelte
{@render children()}
`
The ModeWatcher component will automatically detect the user's preferences and apply/remove the "dark" class, along with the corresponding color-scheme style attribute to the html element.
ModeWatcher will automatically track operating system preferences and apply these if no user preference is set. If you wish to disable this behavior, set the track prop to false:
`svelte`
ModeWatcher can also be configured with a default mode instead of automatically detecting the user's preference.
To set a default mode, use the defaultMode prop:
`svelte`
ModeWatcher can manage the theme-color meta tag for you.
To enable this, set the themeColors prop to your preferred colors:
`svelte`
A function that toggles the current mode.
`svelte
`
A function that sets the current mode. It accepts a string with the value "light", "dark" or "system".
`svelte
`
A function that resets the mode to system preferences.
`svelte
`
A readable store that contains the current mode. It can be "light" or "dark" or undefined if evaluated on the server.
`svelte
`
A writeable store that represents the user's mode preference. It can be "light", "dark" or "system".
A readable store that represents the operating system's mode preference. It can be "light", "dark" or undefined if evaluated on the server. Will automatically track changes to the operating system's mode preference unless this is disabled with the tracking() method which takes a boolean. Normally this is disabled by setting the track prop to false in the

This project is supported by the following beautiful people/organizations:
Published under the MIT license.
Made by @huntabyte, @ollema, and community 💛
Join the Discord server to ask questions, find collaborators, or just say hi!