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.
- β‘ 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.
- For iOS native components, check out @mgcrea/react-native-swiftui.
- For Android native components, check out @mgcrea/react-native-jetpack-compose.
npm install @mgcrea/react-native-tailwind
# or
yarn add @mgcrea/react-native-tailwind
# or
pnpm add @mgcrea/react-native-tailwindUpdate your babel.config.js:
module.exports = {
presets: ["module:@react-native/babel-preset"],
plugins: [
"@mgcrea/react-native-tailwind/babel", // Add this line
],
};Create a type declaration file to enable className prop autocomplete:
// src/types/react-native-tailwind.d.ts
import "@mgcrea/react-native-tailwind/react-native";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>
);
}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" },
});π Full Documentation
- Getting Started - Installation and setup
- Guides - Usage examples and patterns
- API Reference - Complete utility reference
- Advanced - Configuration and customization
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>
);
}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>
);
}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>
);
}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>
);
}Contributions are welcome! Please read our Contributing Guide for details.
- 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.
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.
