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

input-switch-polyfill

v1.9.0

Published

A polyfill for <input type="checkbox" switch>

Readme

<input type="checkbox" switch> Polyfill

This project is a small, zero-dependency polyfill for the HTML switch control <input type="checkbox" switch>.

The polyfill provides a visual switch-style control for checkboxes using the switch attribute, and gracefully defers to native browser support where available.

Installation

Using npm

Install the package as a dependency (for example, in a static site or simple web app):

npm install input-switch-polyfill

This package ships the following files:

  • input-switch-polyfill.js – the polyfill logic
  • input-switch-polyfill.css – the accompanying styles

Using a CDN

<script type="module">
  if (!('switch' in HTMLInputElement.prototype)) {
    await import('https://unpkg.com/input-switch-polyfill/input-switch-polyfill.js');
  }
</script>

Using a simple static copy

Alternatively, copy input-switch-polyfill.js and input-switch-polyfill.css into your project (for example, next to your index.html) and reference them directly.

Usage

Conditionally load the polyfill as an ES module to only apply it when the browser does not already support input[switch] natively, and hide the switch input temporarily to give it a chance to load. This loading pattern prevents flash of unstyled content (FOUC).

<style>
  @keyframes hideBriefly {
    0%,
    100% {
      visibility: hidden;
    }
  }

  label:has(input[switch]),
  input[switch] {
    animation: hideBriefly 2s;
  }
</style>

<noscript>
  <style>
    label:has(input[switch]),
    input[switch] {
      animation: none;
    }
  </style>
</noscript>

<script type="module">
  if (!('switch' in HTMLInputElement.prototype)) {
    await import('./input-switch-polyfill.js');
  } else {
    document.head.insertAdjacentHTML(
      'beforeend',
      `<style>label:has(input[switch]),input[switch]{animation:none;}</style>`
    );
  }
</script>

Then, in your HTML, use checkboxes with the switch attribute:

<label>
  Default
  <input type="checkbox" switch />
</label>

<label>
  Accent color red
  <input type="checkbox" switch style="accent-color: red" />
</label>

<label>
  Accent color #00ff00 default checked
  <input type="checkbox" switch checked style="accent-color: #00ff00" />
</label>

This mirrors the usage in index.html in this repository.

Accent color support

The polyfill reads the computed accent-color of each input[type="checkbox"][switch] and maps it to a CSS custom property --switch-accent. You can:

  • Rely on inherited accent-color
  • Set accent-color inline (as in the examples above)
  • Or set accent-color via CSS rules

The provided input-switch-polyfill.css uses --switch-accent to style the visual switch.

Demo

You can see a demo of this polyfill right in your browser.

Development

Clone the repository and install dependencies:

git clone https://github.com/tomayac/input-switch-polyfill.git
cd input-switch-polyfill
npm install

Start a simple static server (as defined in package.json):

npm start

Then open index.html in your browser (or follow the URL printed by the dev server) to see the demo, which corresponds to the usage shown above.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.