Installation
NativeWind works with both Expo and framework-less React Native projects but Expo provides a more streamlined experience.
Web: If you'd like to use Metro to bundle for a website or App Clip and you are not using Expo, you will need either Expo's Metro config @expo/metro-config
or to manually use Tailwind CLI to generate a CSS file.
- Expo SDK 50+
- Expo SDK 49
- Framework-less
- Next.js
If you'd like to skip manual setup and use NativeWind with Expo, you can use the following command to initialize a new Expo project with NativeWind and Tailwind CSS.
npx create-expo-stack@latest --nativewind
Installation with Expo SDK 50+
1. Install NativeWind
You will need to install nativewind
and it's peer dependencies tailwindcss
, react-native-reanimated
and react-native-safe-area-context
- npm
- yarn
- pnpm
- bun
- Expo
npm install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
yarn add nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
pnpm install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
bun install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
npx expo install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
2. Setup Tailwind CSS
Run npx tailwindcss init
to create a tailwind.config.js
file
Add the paths to all of your component files in your tailwind.config.js file.
/** @type {import('tailwindcss').Config} */
module.exports = {
// NOTE: Update this to include the paths to all of your component files.
content: ["./app/**/*.{js,jsx,ts,tsx}"],
presets: [require("nativewind/preset")],
theme: {
extend: {},
},
plugins: [],
}
Create a CSS file and add the Tailwind directives
@tailwind base;
@tailwind components;
@tailwind utilities;
From here onwards, replace ./global.css
with the relative path to the CSS file you just created
3. Add the Babel preset
module.exports = function (api) {
api.cache(true);
return {
presets: [
["babel-preset-expo", { jsxImportSource: "nativewind" }],
"nativewind/babel",
],
};
};
4. Modify your metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const { withNativeWind } = require('nativewind/metro');
const config = getDefaultConfig(__dirname)
module.exports = withNativeWind(config, { input: './global.css' })
5. Import your CSS file
import "./global.css"
export default App() {
/* Your App */
}
6. Modify your app.json
Switch the bundler to use the Metro bundler
{
"expo": {
"web": {
"bundler": "metro"
}
}
}
7. TypeScript (optional)
Please follow the TypeScript guide.
Installation with Expo SDK 49
1. Install NativeWind
You will need to install nativewind
and it's peer dependencies tailwindcss
, react-native-reanimated
and react-native-safe-area-context
- npm
- yarn
- pnpm
- bun
- Expo
npm install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
yarn add nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
pnpm install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
bun install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
npx expo install nativewind tailwindcss react-native-reanimated@3.16.2 react-native-safe-area-context
2. Setup Tailwind CSS
Run npx tailwindcss init
to create a tailwind.config.js
file
Add the paths to all of your component files in your tailwind.config.js file.
/** @type {import('tailwindcss').Config} */
module.exports = {
// NOTE: Update this to include the paths to all of your component files.
content: ["./app/**/*.{js,jsx,ts,tsx}"],
presets: [require("nativewind/preset")],
theme: {
extend: {},
},
plugins: [],
}
Create a CSS file and add the Tailwind directives
@tailwind base;
@tailwind components;
@tailwind utilities;
From here onwards, replace ./global.css
with the relative path to the CSS file you just created
3. Add the Babel preset
module.exports = function (api) {
api.cache(true);
return {
presets: [
["babel-preset-expo", { jsxImportSource: "nativewind" }],
"nativewind/babel",
],
plugins: [
// Required for expo-router
"expo-router/babel",
"react-native-reanimated/plugin",
]
};
};
4. Modify your metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const { withNativeWind } = require('nativewind/metro');
const config = getDefaultConfig(__dirname, { isCSSEnabled: true })
module.exports = withNativeWind(config, { input: './global.css' })
5. Import your CSS file
import "./global.css"
export default App() {
/* Your App */
}
6. Modify your app.json
Switch the bundler to use the Metro bundler
{
"expo": {
"web": {
"bundler": "metro"
}
}
}
7. TypeScript (optional)
Please follow the TypeScript guide.
Installation with Framework-less React Native
Before installing NativeWind, you will need to initialize your project with the React Native Community CLI.
1. Install NativeWind
You will need to install nativewind
and it's peer dependencies tailwindcss
, react-native-reanimated
and react-native-safe-area-context
- npm
- yarn
- pnpm
- bun
npm install nativewind tailwindcss react-native-reanimated react-native-safe-area-context
yarn add nativewind tailwindcss react-native-reanimated react-native-safe-area-context
pnpm install nativewind tailwindcss react-native-reanimated react-native-safe-area-context
bun install nativewind tailwindcss react-native-reanimated react-native-safe-area-context
Run pod-install
to finish installation of react-native-reanimated
npx pod-install
2. Setup Tailwind CSS
Run npx tailwindcss init
to create a tailwind.config.js
file
Add the paths to all of your component files in your tailwind.config.js file.
/** @type {import('tailwindcss').Config} */
module.exports = {
// NOTE: Update this to include the paths to all of your component files.
content: ["./App.{js,jsx,ts,tsx}"],
presets: [require("nativewind/preset")],
theme: {
extend: {},
},
plugins: [],
}
Create a CSS file and add the Tailwind directives
@tailwind base;
@tailwind components;
@tailwind utilities;
From here onwards, replace ./global.css
with the relative path to the CSS file you just created
3. Add the Babel preset
module.exports = {
- presets: ['<existing presets>'],
+ presets: ['<existing presets>', 'nativewind/babel'],
};
4. Modify your metro.config.js
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
const { withNativeWind } = require("nativewind/metro");
const config = mergeConfig(getDefaultConfig(__dirname), {
/* your config */
});
module.exports = withNativeWind(config, { input: "./global.css" });
5. Import your CSS file
import "./global.css"
export default App() {
/* Your App */
}
6. TypeScript
By default, the React Native Community CLI includes TypeScript support. Subsequently, you will need to follow the TypeScript guide to finish setting up NativeWind in your project.
Installation with Next.js
NativeWind can be used in a Next.js project that is already configured to use Expo or framework-less React Native Web.
Setting up a new Next.js project to use React Native Web is out of scope for these instructions.
NativeWind will only work with the /pages
router or on "use client"
routes. RSC support is in progress.
1. Setup Tailwind CSS
Simply configure Next.js as per the Tailwind CSS Next.js setup guide
2. Add the NativeWind preset
module.exports = {
content: [
'./pages/**/*.{js,jsx,ts,tsx}',
],
+ presets: [require('nativewind/preset')],
theme: {
extend: {},
},
}
3. Update import source
NativeWind requires the jsxImportSource
to be set to nativewind
. The option to configure this depends on how you are compiling your Next.js project.
- SWC
- Babel
Next.js uses a jsconfig.json
/tsconfig.json
file to configure the jsxImportSource
.
{
"compilerOptions": {
"jsxImportSource": "nativewind"
}
}
module.exports = {
presets: ["next/babel"],
+ plugins: [
+ [
+ "@babel/plugin-transform-react-jsx",
+ {
+ runtime: "automatic",
+ importSource: "nativewind",
+ },
+ ],
+ ],
};
4. Transpile NativeWind
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
+ transpilePackages: ["nativewind", "react-native-css-interop"],
}
Common issues
Errors about package imports.
import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
^^^^^^
SyntaxError: Cannot use import statement outside a module
This signals that you have incorrectly setup React Native Web and/or a dependency needs to be added to transpilePackages
. This is out of scope for NativeWind.
Styles are not being applied
A common issue with Next.js is your styles are imported, but are being overridden by another StyleSheet due to the stylesheet import order.
A simple fix is simply make the Tailwind styles a higher specificity.
module.exports = {
content: [
'./pages/**/*.{js,jsx,ts,tsx}',
],
plugins: [require('nativewind/tailwind/css')],
+ important: 'html',
theme: {
extend: {},
},
}