Overview
Uniwind provides built-in platform selectors that allow you to apply styles conditionally based on the platform your app is running on. This is essential for creating platform-specific user experiences in React Native.Platform selectors are resolved at runtime and automatically apply the correct styles for the current platform.
Basic Usage
Use platform selectors directly in yourclassName prop with the syntax platform:utility:
Why Use Platform Selectors?
Platform selectors are superior to React Native’sPlatform.select() API for several reasons:
❌ Not Recommended: Platform.select()
- Requires importing
PlatformAPI - More verbose syntax
- Cannot combine with other utilities easily
- Less readable when multiple platform conditions are needed
✅ Recommended: Platform Selectors
- Clean, declarative syntax
- No extra imports needed
- Easy to combine with other Tailwind utilities
- Better readability and maintainability
- Works seamlessly with theme variants
Supported Platforms
Targets iOS devices (iPhone, iPad). Styles are applied only when running on iOS.
Targets Android devices. Styles are applied only when running on Android.
Targets web browsers. Styles are applied only when running in a web environment (e.g., React Native Web).
Targets both iOS and Android platforms. Styles are applied on mobile platforms but not on web. This is a convenient shorthand when you want to apply the same styles to both iOS and Android.
Targets all TV platforms (Apple TV and Android TV). Styles are applied only when running on a TV device. Requires
isTV: true in your metro.config.js.Targets Apple TV only. Styles are applied only when running on tvOS. Requires
isTV: true in your metro.config.js.Targets Android TV only. Styles are applied only when running on Android TV. Requires
isTV: true in your metro.config.js.Native Selector
Thenative: selector is a convenient shorthand for targeting both iOS and Android platforms simultaneously. Instead of writing duplicate styles for both platforms, you can use native: to apply styles to all mobile platforms at once.
❌ Verbose: Duplicate platform styles
✅ Concise: Using native: selector
TV Selectors
Available in Uniwind 1.5.0+ Uniwind supports TV platforms with dedicated selectors. To enable TV support, setisTV: true in your metro.config.js.
tv: selector targets both Apple TV and Android TV, similar to how native: targets both iOS and Android. Use apple-tv: or android-tv: when you need platform-specific TV styles.
Examples
Platform-Specific Colors
Platform-Specific Spacing
Platform Variants in @layer theme
While platform selectors likeios:, android:, native:, and web: are great for component-level styling, Uniwind also supports platform-specific @variant directives within @layer theme. This allows you to define platform-specific design tokens and CSS variables that affect your entire theme.
Platform
@variant directives in @layer theme are processed at build time and define global theme values, while platform selectors are resolved at runtime for component-specific styles.Theme Configuration
Use@media queries inside @theme to define platform-specific CSS variables in your global.css:
When to Use Each Approach
Understanding when to use platform selectors vs platform@variant directives helps you build better cross-platform apps:
Platform Selectors (ios:, android:, native:, web:)
Platform Selectors (ios:, android:, native:, web:)
Use for component-specific styling
- High flexibility - mix and match on any component
- Best for: Different padding, colors, or layouts for specific UI elements
- Use
native:for shared mobile styles
Platform Variants in @layer theme
Platform Variants in @layer theme
Use for global theme configuration
- Affects entire design system
- Best for: Platform-specific fonts, spacing scales, or brand colors
Platform-Specific Typography
One of the most common use cases is defining platform-appropriate font families:Platform-Specific Spacing
Adjust spacing scales to match platform design guidelines:Combining with Theme Variants
Platform@variant directives work seamlessly with theme variants like dark:
Related
Supported Class Names
Learn about all supported Tailwind classes in Uniwind
Theming
Combine platform selectors with theme variants