
Tailwind V4
Implement Tailwind CSS v4 dark mode with the right variant strategy—system media, class toggle, or data attributes—without FOUC or wrong defaults.
Overview
tailwind-v4 is an agent skill for the Build phase that guides Tailwind CSS v4 dark mode setup across media-query, class-based, and attribute-based strategies.
Install
npx skills add https://github.com/existential-birds/beagle --skill tailwind-v4What is this skill?
- Media-query dark: via prefers-color-scheme with zero config in v4 @import tailwindcss
- Class-based .dark on root for manual theme toggle and user override
- Attribute-based strategy for data-theme or similar selectors
- Theme switching implementation patterns and FOUC avoidance notes
- Pros/cons matrix for docs sites vs apps needing manual dark mode
Adoption & trust: 673 installs on skills.sh; 61 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You upgraded to Tailwind v4 and dark: utilities behave differently than v3, so theme toggles or system sync break or flash wrong colors.
Who is it for?
Indie SaaS and marketing sites on Tailwind v4 that need predictable dark mode without reinventing variant wiring.
Skip if: Projects on Tailwind v3-only configs with no migration plan, or teams using CSS-in-JS without utility classes.
When should I use this skill?
Implementing or migrating dark mode utilities after adopting Tailwind CSS v4.
What do I get? / Deliverables
You pick a documented dark mode strategy, configure v4 imports or darkMode correctly, and ship components with consistent light/dark utility pairs.
- Chosen dark mode strategy
- Root-level theme toggle or media-default behavior
- Component examples with paired dark: classes
Recommended Skills
Journey fit
Styling and theme behavior are canonical Build frontend work before Ship visual QA. Frontend covers Tailwind v4 import setup, dark: variants, and React class patterns for cards and layouts.
How it compares
Pattern reference for v4 dark variants—not a complete component library or accessibility audit checklist.
Common Questions / FAQ
Who is tailwind-v4 for?
Solo frontend builders using Tailwind CSS v4 who need clear dark mode architecture for React or similar component trees.
When should I use tailwind-v4?
During Build frontend when implementing dark:bg and dark:text patterns, choosing system vs manual theme, or fixing FOUC after a v4 migration.
Is tailwind-v4 safe to install?
It is documentation-only guidance; review any linked repo on the Security Audits panel before trusting third-party Tailwind snippets in CI.
SKILL.md
READMESKILL.md - Tailwind V4
# Dark Mode Strategies ## Contents - [Media Query Strategy](#media-query-strategy) - [Class-Based Strategy](#class-based-strategy) - [Attribute-Based Strategy](#attribute-based-strategy) - [Theme Switching Implementation](#theme-switching-implementation) - [Respecting User Preferences](#respecting-user-preferences) --- ## Media Query Strategy Use the system preference for dark mode detection. ### Configuration **Default behavior** (v4): ```css /* No configuration needed - dark: variant works by default */ @import 'tailwindcss'; ``` **Generated CSS**: ```css @media (prefers-color-scheme: dark) { .dark\:bg-slate-900 { background-color: oklch(20.8% 0.042 265.755); } } ``` ### Usage ```tsx export function Card({ children }: { children: React.ReactNode }) { return ( <div className="bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-50"> {children} </div> ); } ``` ### Pros & Cons **Pros**: - Respects system preference automatically - No JavaScript needed - Simple implementation - No FOUC (flash of unstyled content) **Cons**: - Users can't override system preference - No manual toggle control - Changes when system setting changes ### When to Use - Documentation sites - Content-focused websites - Apps where system preference is preferred - No need for manual theme switching ## Class-Based Strategy Toggle dark mode with a `.dark` class on the root element. ### Configuration **Pure v4 approach**: Use a v3 config file with darkMode setting: ```js // tailwind.config.js (for v3 compatibility) module.exports = { darkMode: 'class', // or 'selector' (same as 'class') }; ``` **Note**: In pure v4, the default `dark:` variant uses media queries (`prefers-color-scheme: dark`). To use class-based dark mode, you need to either: 1. Use a v3 config file with `darkMode: 'class'` (shown above) 2. Use `@import "tailwindcss/compat"` and provide a config 3. Define a custom variant with `@custom-variant` ### Generated CSS ```css .dark .dark\:bg-slate-900 { background-color: oklch(20.8% 0.042 265.755); } ``` ### Usage ```tsx export function App() { const [isDark, setIsDark] = useState(false); useEffect(() => { if (isDark) { document.documentElement.classList.add('dark'); } else { document.documentElement.classList.remove('dark'); } }, [isDark]); return ( <div className="bg-white dark:bg-slate-900"> <button onClick={() => setIsDark(!isDark)}> Toggle Theme </button> </div> ); } ``` ### Pros & Cons **Pros**: - Full JavaScript control - User can override system preference - Easy to implement manual toggle - Widely supported pattern **Cons**: - Requires JavaScript - Potential FOUC without SSR handling - Class management overhead ### When to Use - Applications with theme toggle - User preference override needed - Dashboard/admin interfaces - Apps with per-user theme settings ## Attribute-Based Strategy Use a `data-theme` attribute for more semantic theming. ### Configuration (v3 compat) ```js // tailwind.config.js (v3 compat mode) module.exports = { darkMode: ['class', '[data-theme="dark"]'], }; ``` ### Generated CSS ```css [data-theme="dark"] .dark\:bg-slate-900 { background-color: oklch(20.8% 0.042 265.755); } ``` ### Usage ```tsx export function App() { const [theme, setTheme] = useState<'light' | 'dark'>('light'); useEffect(() => { document.documentElement.setAttribute('data-theme', theme); }, [theme]); return ( <div className="bg-white dark:bg-slate-900"> <button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}> Toggle Theme </button> </div> ); } ``` ### Multiple Themes Extend beyond light/dark with multiple theme attributes: ```tsx type Theme = 'light' | 'dark' | 'aviation' | 'high-contrast'; export function App() { const [theme, setTheme] = useState<Theme>('light'); useEffect(() => { document.documentElement.setAttribute('data-theme', theme); }