vincent15000's avatar

How to use TailwindCSS with React ?

Hello,

I'm trying to use TailwindCSS with React. I have installed the package as mentioned in the documentation.

https://tailwindcss.com/docs/guides/create-react-app

I want to use it without any other package like Vite, Parcel, ...

Can you help me please ?

Thanks a lot ;).

V

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

If you are not using any other package like Vite, Parcel, etc., you can still use TailwindCSS with React. You will need to install the TailwindCSS package and create a configuration file. You can then use the create-react-app command to create a React app. After that, you can add the TailwindCSS configuration file to the src folder of the React app. Finally, you can import the TailwindCSS stylesheet into the index.js file of the React app.

// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './tailwind.css';

ReactDOM.render(<App />, document.getElementById('root'));

You can then use TailwindCSS classes in your React components.

// App.js
import React from 'react';

const App = () => {
  return (
    <div className="bg-gray-200 text-gray-700">
      <h1 className="text-2xl font-bold">Hello World!</h1>
    </div>
  );
};

export default App;

For more information, you can refer to the TailwindCSS documentation: https://tailwindcss.com/docs/installation.

1 like

Please or to participate in this conversation.