Skip to content

Effeilo/browserux-theme-switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EN | FR

logo BrowserUX Theme Switcher

BrowserUX Theme Switcher

A modern solution to offer a light/dark theme selector and enhance the user experience across all your web interfaces.

BrowserUX Theme Switcher is a lightweight, accessible, and customizable Web Component designed to easily add a theme switcher button to any website or application. It automatically detects the system theme, remembers the user's preference, and applies the correct theme.


npm version unpkg

Features

  • 🎚 Toggles data-theme="light" / "dark" on <html> or a custom target element
  • 💾 Persists user preference in localStorage
  • 🕶 Detects system preference via prefers-color-scheme on first load
  • 📢 Dispatches a theme-change custom event on every theme change
  • 🧠 Dynamic ARIA labels, multilingual, auto-detected or customizable
  • 🌐 Built-in i18n for 9 languages (en, fr, es, de, ja, ru, pt, it, nl)
  • 🖼 Automatic image swapping via filename convention or explicit data-src-* attributes
  • 🎨 Fully customizable via CSS custom properties (--bux-switch-*)
  • 🧩 Optional Shadow DOM, disable with no-shadow

Installation

npm install browserux-theme-switcher

Or via CDN:

<script type="module" src="https://unpkg.com/browserux-theme-switcher/dist/browserux-theme-switcher.esm.js"></script>

Usage

import 'browserux-theme-switcher';
<browserux-theme-switcher></browserux-theme-switcher>

Parameters

Parameter Type Description
target Attribute CSS selector for the element that receives data-theme
lang Attribute Language code for built-in ARIA labels
data-label-light Attribute Custom ARIA label for activating light mode
data-label-dark Attribute Custom ARIA label for activating dark mode
no-shadow Attribute Disable Shadow DOM encapsulation
style Attribute CSS custom properties for visual customization
theme-change Event Fired on every theme change, e.detail.theme is "light" or "dark"
light-icon Slot Icon displayed on the light side of the toggle
dark-icon Slot Icon displayed on the dark side of the toggle

Documentation

For detailed documentation, see docs/index.md.

Guide

Reference

  • Attributes : target, lang, data-label-*, no-shadow, style
  • Events : theme-change event with payload and use cases
  • Slots : light-icon, dark-icon named slots
  • Utilities : updateImagesByTheme, updateThemeImages

Additional reference

  • Compatibility : browser support, framework compatibility, build formats
  • Contributing : report a bug, suggest an improvement, submit a PR

License

MIT © 2026 Effeilo

About

A modern Web component to manage light/dark themes

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors