npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

svelte-themes

v2.0.10

Published

An abstraction for themes in your Svelte app - port of next-themes for Svelte

Readme

This library is a port of next-themes for Svelte. All credit goes to pacocoursey and all next-themes contributors.

svelte-themes svelte-themes minzip package size Version

An abstraction for themes in your Svelte app - works with any Svelte environment (SvelteKit, Vite, Webpack, etc.)

  • ✅ Perfect dark mode in 2 lines of code
  • ✅ System setting with prefers-color-scheme
  • ✅ Themed browser UI with color-scheme
  • ✅ No FOUC (Flash of Unstyled Content)
  • ✅ Sync theme across tabs and windows
  • ✅ Disable transition flash when changing themes
  • ✅ Force pages to specific themes
  • ✅ Class or data attribute selector
  • ✅ Theme context
  • Svelte 5 ready with modern runes syntax
  • Universal - works with any Svelte setup
  • ✅ SvelteKit dependency

Check out the Live Example to try it for yourself.

Install

$ pnpm add svelte-themes
# or
$ npm install svelte-themes
# or
$ yarn add svelte-themes

Using svelte-themes

Add SvelteTheme to your app's root component. In SvelteKit, this would be your +layout.svelte.

<!-- src/routes/+layout.svelte (SvelteKit) -->
<!-- or src/App.svelte (Vite + Svelte) -->

<script lang="ts">
	import { SvelteTheme } from 'svelte-themes';
	let { children } = $props();
</script>

<SvelteTheme>
	{@render children()}
</SvelteTheme>

Props

  • storageKey = 'theme': Key used to store theme setting in localStorage
  • defaultTheme = 'system': Default theme name. If enableSystem is false, the default theme is light
  • forcedTheme: Forced theme name for the current page (does not modify saved theme settings)
  • enableSystem = true: Whether to switch between dark and light based on prefers-color-scheme
  • enableColorScheme = true: Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons
  • disableTransitionOnChange = false: Optionally disable all CSS transitions when switching themes
  • themes = ['light', 'dark']: List of theme names
  • attribute = 'data-theme': HTML attribute modified based on the active theme
    • accepts class and data-* (meaning any data attribute, data-mode, data-color, etc.)
  • value: Optional mapping of theme name to attribute value
    • Example: { dark: 'dark-theme', light: 'light-theme' }
  • colorScheme: Optional mapping of theme name to color scheme value
    • Example: { 'custom-dark': 'dark', 'custom-light': 'light' }

Reading and updating the theme

Use the useTheme() hook to access and change the active theme.

<script lang="ts">
  import { useTheme } from 'svelte-themes';
  const theme = useTheme();
</script>

<select bind:value={theme.theme}>
  {#each theme.themes as name (name)}
    <option value={name}>{name}</option>
  {/each}
</select>

<button onclick={() => (theme.theme = 'dark')}>Dark mode</button>
<button onclick={() => (theme.theme = 'light')}>Light mode</button>

Theme state

  • theme: Active theme name
  • resolvedTheme: If enableSystem is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to theme
  • systemTheme: If enableSystem is true, represents the System theme preference ("dark" or "light"), regardless what the active theme is
  • themes: The list of themes passed to SvelteTheme (with "system" appended, if enableSystem is true)

Examples

Basic dark/light mode

<script>
  import { SvelteTheme } from 'svelte-themes';
    let { children } = $props();
</script>

<SvelteTheme>
	{@render children()}
</SvelteTheme>

Custom theme names with value mapping

<script>
  import { SvelteTheme } from 'svelte-themes';
    let { children } = $props()
</script>

<SvelteTheme
  themes={['corporate', 'neon', 'vintage']}
  value={{
    corporate: 'theme-corporate',
    neon: 'theme-neon-bright',
    vintage: 'theme-retro'
  }}
  attribute="class"
>
	{@render children()}
</SvelteTheme>

With color scheme mapping

<script>
  import { SvelteTheme } from 'svelte-themes';
  let { children } = $props()
</script>

<SvelteTheme
  themes={['light', 'dark', 'midnight', 'dawn']}
  colorScheme={{
    midnight: 'dark',  // Maps to CSS color-scheme: dark
    dawn: 'light'      // Maps to CSS color-scheme: light
  }}
>
  {@render children()}
</SvelteTheme>