@mgcrea/react-native-tailwind
v0.15.1
Published
Compile-time Tailwind CSS for React Native with zero runtime overhead
Downloads
2,256
Readme
Overview
Compile-time Tailwind CSS for React Native with zero runtime overhead. Transform className props to optimized StyleSheet.create calls at build time using a Babel plugin.
Features
- ⚡ Zero Runtime Overhead - All transformations happen at compile time
- 🔧 No Dependencies - Direct-to-React-Native style generation without tailwindcss package
- 🎯 Babel-only Setup - No Metro configuration required
- 📝 TypeScript-first - Full type safety and autocomplete support
- 🚀 Optimized Performance - Compiles down to StyleSheet.create for optimal performance
- 🔀 Dynamic className - Conditional styles support with compile-time optimization
- 📦 Small Bundle Size - Only includes actual styles used in your app
- 🎯 State Modifiers -
active:,hover:,focus:, anddisabled:modifiers for interactive components - 📱 Platform Modifiers -
ios:,android:, andweb:modifiers for platform-specific styling - 🌓 Color Scheme Modifiers -
dark:andlight:andscheme:modifiers for automatic theme adaptation - 🎨 Custom Colors - Extend the default palette via tailwind.config.*
- 📐 Arbitrary Values - Use custom sizes and borders:
w-[123px],rounded-[20px] - 📜 Special Style Props - Support for
contentContainerClassName,columnWrapperClassName, and more
📊 How It Compares - See how this library stacks up against other React Native styling solutions.
Demo

Quick Start
Installation
npm install @mgcrea/react-native-tailwind
# or
yarn add @mgcrea/react-native-tailwind
# or
pnpm add @mgcrea/react-native-tailwind1. Add Babel Plugin
Update your babel.config.js:
module.exports = {
presets: ["module:@react-native/babel-preset"],
plugins: [
"@mgcrea/react-native-tailwind/babel", // Add this line
],
};2. Enable TypeScript Support (Optional)
Create a type declaration file to enable className prop autocomplete:
// src/types/react-native-tailwind.d.ts
import "@mgcrea/react-native-tailwind/react-native";3. Start Using className
import { View, Text } from "react-native";
export function MyComponent() {
return (
<View className="flex-1 bg-gray-100 p-4">
<Text className="text-xl font-bold text-blue-500">Hello, Tailwind!</Text>
</View>
);
}How It Works
The Babel plugin transforms your code at compile time:
Input (what you write):
<View className={`rounded-lg p-4 ${isSelected ? "bg-blue-500 border border-blue-700" : "bg-gray-200"}`} />Output (what Babel generates):
import { StyleSheet } from "react-native";
<View
style={[
_twStyles._rounded_lg,
_twStyles._p_4,
isSelected ? _twStyles._bg_blue_500_border_border_blue_700 : _twStyles._bg_gray_200,
]}
/>;
const _twStyles = StyleSheet.create({
_rounded_lg: { borderRadius: 8 },
_p_4: { padding: 16 },
_bg_blue_500_border_border_blue_700: { backgroundColor: "#3B82F6", borderWidth: 1, borderColor: "#1D4ED8" },
_bg_gray_200: { backgroundColor: "#E5E7EB" },
});Documentation
- Getting Started - Installation and setup
- Guides - Usage examples and patterns
- API Reference - Complete utility reference
- Advanced - Configuration and customization
Examples
Dynamic Styles
import { useState } from "react";
import { Pressable, Text } from "react-native";
export function ToggleButton() {
const [isActive, setIsActive] = useState(false);
return (
<Pressable
onPress={() => setIsActive(!isActive)}
className={isActive ? "bg-green-500 p-4" : "bg-red-500 p-4"}
>
<Text className="text-white">{isActive ? "Active" : "Inactive"}</Text>
</Pressable>
);
}State Modifiers
import { Pressable, Text } from "@mgcrea/react-native-tailwind";
export function MyButton() {
return (
<Pressable className="bg-blue-500 active:bg-blue-700 p-4 rounded-lg">
<Text className="text-white font-semibold">Press Me</Text>
</Pressable>
);
}Dark Mode
import { View, Text } from "react-native";
export function ThemeCard() {
return (
<View className="bg-white dark:bg-gray-900 p-4 rounded-lg">
<Text className="text-gray-900 dark:text-white">Adapts to device theme</Text>
</View>
);
}Platform-Specific Styles
import { View, Text } from "react-native";
export function PlatformCard() {
return (
<View className="p-4 ios:p-6 android:p-8 bg-white rounded-lg">
<Text className="text-base ios:text-blue-600 android:text-green-600">Platform-specific styles</Text>
</View>
);
}Contributing
Contributions are welcome! Please read our Contributing Guide for details.
Credits
- Tailwind CSS - The utility-first CSS framework that revolutionized the way we style applications. If you enjoy this library, consider supporting them by purchasing Tailwind Plus.
Authors
MIT License
Copyright (c) 2025 Olivier Louvignes <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.