DEV Community

Cover image for Set Up Tailwind CSS in a React JS Project
ziontutorial
ziontutorial

Posted on

2

Set Up Tailwind CSS in a React JS Project

If you don’t have a React app already, create one:

npx create-react-app my-app
cd my-app
Enter fullscreen mode Exit fullscreen mode
  1. Install Tailwind CSS Run the following command to install Tailwind CSS and its dependencies:
npm install -D tailwindcss postcss autoprefixer
Enter fullscreen mode Exit fullscreen mode

Then initialize Tailwind CSS:

npx tailwindcss init

Enter fullscreen mode Exit fullscreen mode

This will create a tailwind.config.js file in your project.

  1. Configure Tailwind Edit the tailwind.config.js file to configure the content paths. Replace the content key with the following:
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}", // Scan these files for Tailwind classes
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};

Enter fullscreen mode Exit fullscreen mode
  1. Add Tailwind Directives to CSS In the src folder, locate or create a file called index.css. Add the following Tailwind directives:
@tailwind base;
@tailwind components;
@tailwind utilities;

Enter fullscreen mode Exit fullscreen mode
  1. Import CSS in React Ensure index.css is imported into your project. In the src/index.js file, you should have:
import './index.css';

Enter fullscreen mode Exit fullscreen mode
  1. Start the Development Server Run your React app to see Tailwind CSS in action:
npm start

Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more