- Creates inputs for
auto
,light
anddark
. - Stores the selection in
localStorage
(if it is notauto
) and selects the correct input on upcoming page loads. - Can use Light DOM instead of markup generated by the Web Component.
If you want to toggle between more than auto
, light
and dark
themes, you can use themes
property. The value should be a space separate list of theme names.
By default, the name
of the input elements is theme
(or theme-{n}
if you have more than on theme-toggle
on a page).
You can change this by using the name
attribute.
Please checkout these examples on how to use the Web Component.
Please note that this Web Component does not add any classes or attributes to the DOM.
Instead you can :has()
to apply the correct theme to your page. Please check out this blog post for an example: https://www.mgrossklaus.de/notes/2023-02-04-implementing-a-theme-toggle-with-html-and-css-only-almost/.