Remix
Adding dark mode to your remix app.
Modify your tailwind.css file
Add :root[class~="dark"] to your tailwind.css file. This will allow you to use the dark class on your html element to apply dark mode styles.
app/tailwind.css
Install remix-themes
Start by installing remix-themes:
Create a session storage and theme session resolver
app/sessions.server.tsx
Set up Remix Themes
Add the ThemeProvider to your root layout.
app/root.tsx
Add an action route
Create a file in /routes/action.set-theme.ts. Ensure that you pass the filename to the ThemeProvider component. This route it's used to store the preferred theme in the session storage when the user changes it.
app/routes/action.set-theme.ts
Add a mode toggle
Place a mode toggle on your site to toggle between light and dark mode.
components/mode-toggle.tsx