next-themes-dark-mode
Skill0 starsChanged 4 months agoMITView on GitHub
Dark mode with next-themes and Tailwind: ThemeProvider setup, class strategy, system preference, flash prevention, and theme toggle component. Use when adding dark mode, theme switching, or color-scheme support to Next.js apps.
- Installs packages
In this repository23 other files it gives its agents.
- client-document-exportSkill
- cloudflare-turnstile-nextjsSkill
- ga4-analytics-nextjsSkill
- git-repo-privacy-auditSkill
- hardened-contact-form-nextjsSkill
- html-semantic-markupSkill
- multi-step-wizard-flowSkill
- nextjs-api-routesSkill
- nextjs-app-routerSkill
- nextjs-seo-metadataSkill
- nextjs-ui-foundationSkill
- playwright-e2e-testingSkill
- react-components-patternsSkill
- react-hooks-patternsSkill
- recharts-dashboardSkill
- resend-email-nextjsSkill
- server-pdf-playwrightSkill
- shadcn-ui-setupSkill
- specialized-form-inputsSkill
- tailwind-css-v4Skill
- vitest-unit-testingSkill
- web-accessibility-wcagSkill
- zustand-persist-stateSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 59
Use semantic tokens (bg-background) mapped in @theme.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Dark Mode (next-themes)
Install
npm install next-themesProvider
// components/providers/theme-provider.tsx
"use client";
import { ThemeProvider as NextThemesProvider } from "next-themes";
export function ThemeProvider({ children }: { children: React.ReactNode }) {
return (
<NextThemesProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
{children}
</NextThemesProvider>
);
}Wrap in root layout inside <body>.
HTML attribute
<html lang="en" suppressHydrationWarning>Required — theme class applied to <html> before hydration.
Tailwind v4 dark variant
@import "tailwindcss";
@custom-variant dark (&:where(.dark, .dark *));Components: bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-100.
CSS variables approach
:root { --background: #f8fafc; --foreground: #0a1929; }
.dark { --background: #0a1929; --foreground: #f0f4f8; color-scheme: dark; }Use semantic tokens (bg-background) mapped in @theme.
Theme toggle
"use client";
import { useTheme } from "next-themes";
import { Moon, Sun } from "lucide-react";
export function ThemeToggle() {
const { theme, setTheme, resolvedTheme } = useTheme();
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
if (!mounted) return <Button variant="ghost" size="icon" aria-label="Toggle theme" />;
return (
<Button
variant="ghost"
size="icon"
aria-label="Toggle theme"
onClick={() => setTheme(resolvedTheme === "dark" ? "light" : "dark")}
>
{resolvedTheme === "dark" ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
</Button>
);
}Mount guard prevents hydration mismatch on icon.
Touch target
Mobile toggle: minimum 44×44px hit area (size="icon" + padding or min-h-11 min-w-11).
Charts / images in dark mode
- Recharts: set axis/grid stroke colors for dark backgrounds
- Export capture: test both themes; some libs capture computed styles at click time
Anti-patterns
- Storing theme only in localStorage without next-themes (flash on load)
- Hardcoded light colors without
dark:counterparts on marketing + app shells enableTransitionOnChangewith heavy CSS transitions (jarring theme switch)
Pair with: tailwind-css-v4, nextjs-ui-foundation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

