
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
tailwindcss-react-native
Advanced tools
Use Tailwindcss in your cross-platform React Native applications
tailwindcss-react-native uses Tailwind CSS as high-level scripting language to create a universal design system. Styled components can be shared between all React Native platforms, using the best style engine for that platform (e.g. CSS StyleSheet or StyleSheet.create). It's goals are to to provide a consistent styling experience across all platforms, improving Developer UX, component performance and code maintainability.
tailwindcss-react-native processes your styles during your application build, and uses a minimal runtime to selectively apply reactive styles (eg changes to device orientation, light dark mode).
:point_right: This example uses Babel which is one of the many setups available.
import { Pressable, View, Text } from "react-native";
/**
* A button that changes color when hovered or pressed
* The text will change font weight when the Pressable is pressed
*/
export function MyFancyButton(props) {
return (
<Pressable className="component bg-violet-500 hover:bg-violet-600 active:bg-violet-700">
<Text className="font-bold component-active:font-extrabold" {...props} />;
</Pressable>
);
}
All documentation is on our website https://tailwindcss-react-native.vercel.app
You can use the Babel plugin to instantly start writing code! This will also enable your editor's language support and provide features such as autocomplete with no extra setup!
import { Text } from "react-native";
export function BoldText(props) {
return <Text className="text-bold" {...props} />;
}
Usage of Babel is optional! You can use the Component API to be more explicit about what gets the styles.
import { Text } from "react-native";
import { styled } from "tailwindcss-react-native";
const StyledText = styled(Text);
export function BoldText(props) {
return <StyledText className="text-bold" {...props} />;
}
You still have the ability to perform conditional logic and built up complex style objects.
import { Text } from "react-native";
export function MyText({ bold, italic, lineThrough, ...props }) {
const classNames = [];
if (bold) classNames.push("font-bold");
if (italic) classNames.push("italic");
if (lineThrough) classNames.push("line-through");
return <Text className={classNames.join(" ")} {...props} />;
}
Additional options can improve compatibilty with existing RN libraries
import { Text } from "react-native";
import { styled } from "tailwindcss-react-native";
import { Svg, Circle, Rect } from "react-native-svg";
/**
* These components can now use the "stroke" & "fill" props with Tailwind classes
* They will use inline-props on native, and className on web.
*/
const StyledCircle = styled(Circle, { classProps: ["stroke", "fill"] });
const StyledRect = styled(Rect, { classProps: ["stroke", "fill"] });
export function BoldText(props) {
return (
<Svg height="50%" width="50%" viewBox="0 0 100 100">
<StyledCircle
cx="50"
cy="50"
r="45"
stroke="stroke-blue-500 stroke-2"
fill="color-green-500"
/>
<StyledRect
x="15"
y="15"
width="70"
height="70"
stroke="stroke-red-500 stroke-2"
fill="color-yellow-500"
/>
</Svg>
);
}
Lastly useTailwind() can be used for manual styling or situations where styled cannot be used.
:warning: This is a example of
useTailwind()that you shouldn't use in practice. There are often more performant patterns thanuseTailwind()and it should be used as a last resort. Please see our docs for more information.
import { ActivityIndicator } from "react-native";
export function MyText({ bold, italic, lineThrough, ...props }) {
const tw = useTailwind();
const { color } = useTailwind("color-black dark:color-white");
return <ActivityIndicator color={color} />;
}
This example uses Babel as it provides the fastest setup. There are more setup configurations and in-depth guides on our website
npx create-react-native-app my-tailwind-native-app;
Choose "Default new app"
Then change your cwd to the folder containing the project
cd my-tailwind-native-app
You will need to install tailwindcss-react-native and it's peer dependency tailwindcss.
yarn add tailwindcss-react-native
yarn add tailwindcss -D
Run npx tailwindcss init to create a tailwind.config.ts file
Add the paths to all of your component files in your tailwind.config.js file.
// tailwind.config.js
module.exports = {
- content: [],
+ content: ["./App.{js,jsx,ts,tsx}", "./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
}
Modify your babel.config.js
// babel.config.js
module.exports = {
- plugins: [],
+ plugins: ["tailwindcss-react-native/babel"],
};
Modify your App.js to add the TailwindProvider
// App.js
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
+ import { TailwindProvider } from 'tailwindcss-react-native';
export default function App() {
return (
+ <TailwindProvider>
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
+ </TailwindProvider>
);
}
Start writing code!
import React from 'react';
- import { StyleSheet, Text, View } from 'react-native';
+ import { Text, View } from 'react-native';
import { TailwindProvider } from 'tailwindcss-react-native';
export default function App() {
return (
<TailwindProvider>
- <View style={styles.container}>
+ <View className="flex-1 items-center justify-center bg-white">
<Text>Open up App.js to start working on your app!</Text>
</View>
</TailwindProvider>
);
}
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#fff',
- alignItems: 'center',
- justifyContent: 'center',
- },
- });
FAQs
Use Tailwindcss in your cross-platform React Native applications
The npm package tailwindcss-react-native receives a total of 663 weekly downloads. As such, tailwindcss-react-native popularity was classified as not popular.
We found that tailwindcss-react-native demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.