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
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
Add the ModeWatcher component
Import the
ModeWatcher component and use it in your page with the client:load directive:src/pages/index.astro
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.