NativeWind provides seamless dark mode support using the standard dark: variant from Tailwind CSS. It automatically responds to the system color scheme and provides utilities for manual control.
Use the dark: variant to apply styles when dark mode is active:
import { View, Text } from 'react-native';export default function App() { return ( <View className="bg-white dark:bg-gray-900"> <Text className="text-gray-900 dark:text-white"> This text adapts to the color scheme </Text> </View> );}
The dark: variant automatically applies when the system is set to dark mode. No additional configuration required.
Test your dark mode implementation across different scenarios:
1
Test system theme switching
Change your device’s system theme and verify your app responds correctly:
iOS: Settings > Display & Brightness > Appearance
Android: Settings > Display > Dark theme
Simulator: Device menu > Appearance
2
Test manual theme controls
If you provide manual theme switching, verify it works independently of system settings:
import { Appearance } from 'react-native';// Test in your componentAppearance.setColorScheme('dark');Appearance.setColorScheme('light');Appearance.setColorScheme(null); // System
3
Verify contrast ratios
Check that all text meets WCAG accessibility guidelines:
Don’t just invert colors. Adjust brightness levels for optimal readability:
// Good: Adjusted brightness<View className="bg-gray-100 dark:bg-gray-800"> <Text className="text-gray-900 dark:text-gray-100"> Readable in both modes </Text></View>// Avoid: Simple inversion can lack contrast<View className="bg-gray-100 dark:bg-gray-900"> <Text className="text-gray-900 dark:text-gray-100"> Too much contrast in dark mode </Text></View>
Test with actual users
Different people perceive dark mode differently. Gather feedback and iterate:
Some users prefer darker backgrounds (#000 vs #111)
Text contrast preferences vary
Color perception changes in dark mode
Consider images and illustrations
Adjust images and illustrations for dark mode when needed:
<Image source={colorScheme === 'dark' ? darkLogo : lightLogo} className="w-32 h-32"/>{/* Or use tint for icons */}<Image source={icon} className="tint-gray-900 dark:tint-white"/>
Pure black backgrounds (#000000) can cause eye strain and make text harder to read. Consider using dark grays like bg-gray-900 (#111827) instead.
Always provide users the option to choose their preferred theme, even if it differs from their system setting. Some users have specific accessibility needs that require a particular color scheme.
Ensure your dark mode implementation is accessible: