Overview
The NativeWind Tailwind CSS plugin extends Tailwind with React Native-specific functionality. It provides the@map variant for mapping CSS properties to platform-specific style names, enabling advanced style transformations.
Installation
Import the plugin in your Tailwind configuration:Plugin Type
plugin.withOptions() API, which allows for future extensibility with custom options.
Configuration
Basic Setup
Add the plugin to yourtailwind.config.js or tailwind.config.ts:
tailwind.config.js
With Tailwind CSS v4
tailwind.config.ts
CommonJS Syntax
tailwind.config.js
The @map Variant
The primary feature of the NativeWind plugin is the@map variant, which enables CSS property mapping for React Native.
Syntax
Parameters
The CSS property name to map. This value is automatically converted to kebab-case.
The target style property name in React Native. Used when remapping property names.
Basic Usage
Map a style value to a different property:With Value and Modifier
Map a specific value to a specific target:Modifier Only
Move the last style value to a custom property:How It Works
The plugin uses Tailwind’smatchVariant API to create a custom variant:
- Value Transformation - Converts camelCase to kebab-case
- Escape Handling - Properly escapes special characters like
& - @media Wrapper - Wraps mappings in
@media allto work around Tailwind’s internal behavior
Kebab-Case Conversion
The plugin automatically converts property names:Advanced Usage
Platform-Specific Mappings
Combine with platform modifiers:Responsive Mappings
With Custom Utilities
Define custom utilities that work with@map:
tailwind.config.js
Technical Details
@media all Wrapper
The
@media all wrapper is a workaround for Tailwind CSS internals. Without it, the @nativeMapping block wouldn’t properly contain the styles.Variant Patterns
The plugin handles three distinct patterns:-
Value + Modifier:
@map-[value]/[modifier]:class- Maps specific value to target property
- Example:
@map-shadowColor/elevation:shadow-lg
-
Modifier Only:
@map/[modifier]:class- Moves last style value to modifier
- Example:
@map/customProp:text-red-500
-
Value Only:
@map-[value]:class- Maps to native property by value name
- Example:
@map-textColor:text-blue-500
Use Cases
Shadow to Elevation Mapping
Convert iOS shadow styles to Android elevation:Custom Property Mappings
Map Tailwind utilities to custom native properties:Style Transformations
Transform web-style properties to native equivalents:Limitations
- Only works with properties that exist in React Native’s style system
- May produce verbose CSS output
- Requires understanding of both web and native style property names
Related
- Metro Configuration - Configure Metro bundler
- Babel Configuration - Configure Babel plugin
- Custom Styles Guide - Learn about custom styling
- Tailwind Config Guide - Tailwind configuration