class strategy from Tailwind CSS to support dark mode toggling. See the Tailwind CSS documentation for more information.
How you add the dark class to the html element is up to you. In this guide, we’ll take a look at enabling dark mode toggling with mode-watcher.
Usage
1
Create an inline theme script
This script will, in part, keep and track the dark mode value in
localStorage and prevent FUOC.src/pages/index.astro
2
Install mode-watcher
3
Add the ModeWatcher component
Import the
ModeWatcher component and use it in your page with the client:load directive:src/pages/index.astro
4
Create a mode toggle
Create a mode toggle on your site to toggle between light and dark mode.You can create either a light switch toggle or a dropdown menu toggle. The implementation details will depend on your specific UI components.
5
Add mode toggle to page
Add the mode toggle to the page (also with the
client:load directive):src/pages/index.astro