Back to ✨ Feature Scaffolding

Implement Dark Mode

UITailwindTheming
---
description: Add dark mode support using next-themes
---

1. **Install next-themes**:
- Install the library.
// turbo
- Run npm install next-themes

2. **Add Provider**:
- Wrap your app in app/layout.tsx.
import { ThemeProvider } from 'next-themes';

export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<body>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
{children}
</ThemeProvider>
</body>
</html>
);
}


3. **Configure Tailwind**:
- Ensure darkMode: 'class' is in tailwind.config.ts.
export default {
darkMode: 'class',
// ... rest of config
}


4. **Create Toggle Button**:
- Build a theme switcher component.
'use client'
import { useTheme } from 'next-themes';
import { useEffect, useState } from 'react';

export function ThemeToggle() {
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();

useEffect(() => setMounted(true), []);
if (!mounted) return null;

return (
<button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
{theme === 'dark' ? '🌞' : '🌙'}
</button>
);
}


5. **Pro Tips**:
- Use suppressHydrationWarning on the <html> tag to prevent hydration warnings.
- The useEffect check ensures the component only renders after hydration.
By Antigravity Team

How to Use This Workflow

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/workflows/
  3. Save the file as implement-dark-mode-next-themes-tailwind.md
  4. In Antigravity, type /implement_dark_mode_next_themes_tailwind or just describe what you want to do

Learn more about workflows →

Related Workflows

Recommended Rules

View more rules →

Recommended MCP Servers

View more MCP servers →

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide