Nov 28, 2022

Using Tailwind CSS in React Native

Let us understand what is Tailwind CSS, its advantages, and how to use it in React Native

Author

Syed Minhaj HussainSyed Minhaj HussainSoftware Engineer - II
Using Tailwind CSS in React Native

In this article we will learn how to use Tailwind CSS in React Native applications. But before we begin, we should know what Tailwind CSS is and how it can be helpful in developing good user interfaces.

What is Tailwind CSS?

A utility-first CSS framework packed with classes that can be composed to build any user interface, directly in your HTML file. The good thing of this framework is it doesn't impose any design specification, which means you're not restricted for creating any design of your choice.

It is highly performant and small in size, Tailwind automatically removes all unused CSS when building for production, it ships the smallest CSS bundle possible. In fact, most Tailwind projects ship less than 10kB of CSS to the client.

Now, we've understood what Tailwind is, let us use see how we define classes in our React App using JSX. For example, you could style a button with just a few classes which Tailwind offers.

html
<button className="bg-blue-500 hover:bg-blue-700 
    text-white font-bold py-[5rem] px-4 rounded ml-4 mt-4">
  Button
</button>

Let us move forward by understanding how can we use Tailwind CSS in React Native application.

NativeWind

It is a package that uses Tailwind CSS as scripting language to create a universal style system for React Native. NativeWind components can be shared between platforms and will output their styles as CSS Stylesheet on web and Stylesheet for native.

React Native's Stylesheet system only provides static styles, with other features left for the user to implement. By using NativeWind you can focus on writing your system instead of building your own custom style system.

Getting started

Step 1. Set up project

To set up our project, we'll scaffold a new react Native app using react-native init. If you have already done this, skip this process, otherwise, run the command below:

js
npx react-native init my-nativewind-app

Choose "Default new app" and then move into the project's directory.

js
cd my-nativewind-app

Step 2. Install NativeWind

Install nativewind and it's peer dependency tailwindcss.

js
yarn add nativewind
yarn add --dev tailwindcss

Step 3. Set up Tailwind

Setup Tailwind CSS, run the command npx tailwindcss init to create a tailwind.config.js file.

js
  // tailwind.config.js

  module.exports = {
  - content: [],
  + content: ["./App.{js,jsx,ts,tsx}", "./src/**/*.{js,jsx,ts,tsx}"],
    theme: {
      extend: {},
    },
    plugins: [],
  };

Step 4. Add Babel plugin

Add the Babel plugin, modify your babel.config.js.

js
  // babel.config.js
  module.exports = {
  - plugins: [],
  + plugins: ["nativewind/babel"],
  };

Thats it!

js
  import { StatusBar } from 'expo-status-bar';
  import React from 'react';
  import { Text, View } from 'react-native';

  export default function App() {
    return (
    <View className="flex-1 items-center justify-center bg-white">
        <Text className="text-gray-400 text-md font-bold mt-2">
            Open up App.js to start working on your app!
        </Text>
        <StatusBar style="auto" />
      </View>
    );
  }

TypeScript

NativeWind extends the React Native types via declaration merging. The simplest method to include the types is to create a new app.d.ts file and add a triple-slash directive referencing the types.

js
  /// <reference types="nativewind/types" />

Theme Configuration

Customizing the default theme for your project.

The theme section of your tailwind.config.js file is where you define your project’s color palette, type scale, fonts, border radius values, and more.

js
// tailwind.config.js
module.exports = {
  theme: {
      extend: {
         colors: {
            'blue': '#1fb6ff',
            'purple': '#7e5bef',
            'gray': '#8492a6',
                },
         spacing: {
             '2x': '20px',
             '3x': '30px',
                },
         borderRadius: {
             '4xl': '40px',
                }
            }
          }
       };

If you need theme values at runtime, its best to retrieve them directly from tailwind or your tailwind.config.js.

js
import colors from "tailwindcss/colors";

export function MyActivityIndicator(props) {
  return <ActivityIndicator size="small" color={colors.blue} {...props}  />;
};

Creating custom components

NativeWind also allow us to create our own components along with Tailwind classes.

Passing classes (or) style to components

When passing styles between components, they are compiled on the parent and then passed as a style prop to the child.

js
function MyComponent({ style }) {
  // You need to use style, className's classes are compiled into style object & passed as props.
  return <Text style={style} />;
}

<MyComponent className="font-bold" />

styled()

styled() is a Higher-Order Component which allows your component to accept either the tw or className props. These props are compiled into Stylesheet objects and passed to your component via the style prop.

js
import React from 'react';
import { Text, View, TouchableOpacity } from "react-native";
import { styled } from "nativewind";

const StyledText = styled(Text);
const StyledView = styled(View);
const StyledTouch = styled(TouchableOpacity)

function App() {
const onPress = () => console.log("Pressed");
  return (
    <StyledView className="flex-1">
      <StyledText tw="font-bold">Hello world.</StyledText>
      <StyledText className="font-bold">Hello world.</StyledText>
      <StyledTouch className="text-3xl p-5" onPress={onPress} >
          <StyledText className="font-medium text-orange-600">
            Press Here
          </StyledText>
      <StyledTouch>
    </StyledView>
  );
}

Conclusion

To sum up, Tailwind CSS won't restrict you for creating any design of your choice. You define that with adding classes for the required design.

I believe, this would be enough for getting started with Tailwind CSS in React Native. If you want to explore more, you can visit NativeWind and experiment.

html
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-[5rem] px-4 rounded ml-4 mt-4">
Button
</button>

Subscribe to Our Newsletter

RELATED ARTICLES

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Why Legacy Systems Block Real-Time AI Decision-Making
Business

Aug 4, 2026

Why Legacy Systems Block Real-Time AI Decision-Making
Learn how legacy systems limit real-time AI decision-making and what businesses can do to build an AI-ready infrastructure.
What Makes an AI Product Enterprise-Ready? A Business Leader’s Perspective
Business

Aug 4, 2026

What Makes an AI Product Enterprise-Ready? A Business Leader’s Perspective
Most AI pilots never make it to production. Here are the five questions business leaders should ask before approving, buying, or scaling an AI product.
Building AI-Powered Banking CRM Platforms Without Replacing Core Banking Systems
Business

Jul 31, 2026

Building AI-Powered Banking CRM Platforms Without Replacing Core Banking Systems
Banks can modernize CRM with AI without replacing their core banking systems. This guide covers the architecture, use cases, governance, and roadmap to do it.
AI in Fintech: Everyone's Talking, Few are Shipping
Business

Jul 30, 2026

AI in Fintech: Everyone's Talking, Few are Shipping
This blog covers the key engineering, governance, and compliance principles required to build production-ready AI systems for financial services.
ERP and MES Integration for U.S. Pharma Manufacturers: A Roadmap to Achieve Zero-Error Production and End-to-End Traceability
Business

Jul 27, 2026

ERP and MES Integration for U.S. Pharma Manufacturers: A Roadmap to Achieve Zero-Error Production and End-to-End Traceability
A strategic roadmap for U.S. pharma leaders integrating ERP and MES to reduce production errors, accelerate batch release, strengthen compliance readiness, and enable end-to-end traceability across manufacturing sites.
How to Build Medical Device Software with AI: Compliance, Architecture, and Development Process
Business

Jul 24, 2026

How to Build Medical Device Software with AI: Compliance, Architecture, and Development Process
A guide for engineering leaders on building compliant, production-ready AI medical device software, from architecture to FDA clearance.

The Right Conversation Can Save You Six Months.

Whether you’re navigating AI adoption, modernizing legacy systems, or scaling a product - we start by listening. No pitch deck. No template. A real conversation.