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 🙏

© 2026 – Pkg Stats / Ryan Hefner

theme-change

v3.0.4

Published

Change CSS theme with toggle, buttons or select using CSS Variables and localStorage

Downloads

46,756

Readme

🎨 CSS Theme Change

Tiny helper for CSS themes.

  • One HTML attribute data-set-theme to set theme theme.
  • Works with button, select, and checkbox
  • Persists theme in localStorage
  • Syncs all matching data-set-theme controls

Demo

  • CodePen: https://codepen.io/saadeghi/pen/OJypbNM?editors=1000

image

Quick start

CDN

<script src="https://cdn.jsdelivr.net/npm/theme-change@latest/index.js"></script>

NPM

npm i theme-change@latest
import { themeChange } from "theme-change";

themeChange();

Use themeChange(false) when controls are mounted after initial page load.

Framework snippets

import { useEffect } from "react";
import { themeChange } from "theme-change";

useEffect(() => {
  themeChange(false);
}, []);
import { onMounted } from "vue";
import { themeChange } from "theme-change";

export default {
  setup() {
    onMounted(() => {
      themeChange(false);
    });
  },
};
import { onMount } from "svelte";
import { themeChange } from "theme-change";

onMount(() => {
  themeChange(false);
});
---
import { themeChange } from "theme-change";
---

<script>
  themeChange(false);
</script>

CSS setup

Use daisyUI themes, or define your own theme tokens:

:root {
  --my-color: #fff;
}
[data-theme="dark"] {
  --my-color: #000;
}
[data-theme="pink"] {
  --my-color: #ffabc8;
}
body {
  background-color: var(--my-color);
}

HTML patterns

| Pattern | Preview | Minimal code | | --- | --- | --- | | Button set | | <button data-set-theme="dark">Dark</button> | | Button rotate | | <button data-set-theme="dark,light,pink">Rotate</button> | | Select | | <select data-set-theme><option value="">Default</option><option value="dark">Dark</option></select> | | Checkbox | | <input type="checkbox" value="dark" data-set-theme /> |

Notes:

  • For checkbox: checked sets theme, unchecked clears theme.
  • For rotate button: each click moves to the next item and loops.
  • Controls with the same data-key stay in sync.

Optional attributes

data-act-class

<button data-set-theme="" data-act-class="ACTIVE"></button>
<button data-set-theme="dark" data-act-class="ACTIVE"></button>
<button data-set-theme="pink" data-act-class="ACTIVE"></button>

data-act-attribute

Like data-act-class, but sets an arbitrary HTML attribute (instead of a class) on a button while its theme is active, and removes it when inactive. Useful for accessibility state such as aria-pressed or aria-current.

<!-- name:value — active: aria-pressed="true", inactive: attribute removed -->
<button data-set-theme="dark" data-act-attribute="aria-pressed:true"></button>

<!-- bare name (no colon) — boolean presence: active: aria-current="", inactive: removed -->
<button data-set-theme="pink" data-act-attribute="aria-current"></button>

Notes:

  • Syntax is name[:value]. Only the first colon splits name and value, so the value may itself contain colons (e.g. data-act-attribute="title:Active: dark").
  • When inactive the attribute is fully removed (not set to a falsy value).
  • Button-only, same as data-act-class — ignored on <select> and checkbox controls.
  • Can be combined with data-act-class on the same element.
  • Also works with the legacy data-toggle-theme buttons.

data-key

<select data-set-theme data-key="admin-panel"></select>
<button data-set-theme="dark" data-key="front-page"></button>
<input type="checkbox" value="pink" data-set-theme data-key="premium-user-theme" />

Backward compatibility

Legacy v2 attributes still work:

  • data-toggle-theme
  • data-choose-theme