--- name: tailwindcss-responsive-darkmode description: Tailwind CSS responsive design and dark mode implementation patterns for 2025/2026 --- # Tailwind CSS Responsive Design & Dark Mode (2025/2026) ## Responsive Design ### Mobile-First Approach (Industry Standard 2025/2026) Tailwind uses a mobile-first breakpoint system. With over 60% of global web traffic from mobile devices and Google's mobile-first indexing, this approach is essential. **Key Principle**: Unprefixed utilities apply to ALL screen sizes. Breakpoint prefixes apply at that size AND ABOVE. ```html
Responsive paragraph text
``` #### Responsive Spacing ```htmlContent
Primary text
Secondary text
Muted text
Smoothly scaling body text.
``` ### 2. Use Semantic Dark Mode Colors ```css @theme { /* Instead of raw colors, use semantic names */ --color-surface: oklch(1 0 0); --color-surface-dark: oklch(0.15 0 0); --color-on-surface: oklch(0.1 0 0); --color-on-surface-dark: oklch(0.95 0 0); } ``` ### 3. Test All Breakpoints Use the debug-screens plugin during development: ```bash npm install -D @tailwindcss/debug-screens ``` ```css @plugin "@tailwindcss/debug-screens"; ``` ### 4. Reduce Repetition with Components ```css /* components.css */ @layer components { .card { @apply bg-white dark:bg-gray-800 rounded-lg p-6 shadow-sm; } .section { @apply py-12 md:py-16 lg:py-24; } } ``` ### 5. Consider Color Contrast Ensure sufficient contrast in both light and dark modes (WCAG 2.2): - **Normal text**: 4.5:1 contrast ratio minimum - **Large text (18pt+)**: 3:1 contrast ratio minimum - **Interactive elements**: 3:1 against adjacent colors ```html ``` ### 6. Reduced Motion Preference Respect users who prefer reduced motion: ```html
```
### 8. Safe Area Handling (Notched Devices)
```css
@utility safe-area-pb {
padding-bottom: env(safe-area-inset-bottom);
}
```
```html
```