DEV Community

Brennan Davis
Brennan Davis

Posted on

Tailwind, Flowbite, React, oh my.

If you are familiar with CSS, you probably have found it slightly frustrating to troubleshoot your styling. You made your styling code in your css file, you double check your names or ids, then you open your browser to see if anything has changed. It's a laborious workflow. Fortunately, their are styling frameworks to help you style your front-end with ease. Specifically, Tailwind is a styling framework that can speed your up your workflow so you can worry about more important things.

Tailwind is a framework for css that uses class names to style your projects. The documentation on their website is very clear and concise.

To install Tailwind for React:

Make a new project:

npx create-react-app my-project
cd my-project
Enter fullscreen mode Exit fullscreen mode

***It's important to be in your react directory when you install Tailwind.

Next install Tailwind:

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Enter fullscreen mode Exit fullscreen mode

These commands will install taildwind, postcss, and autoprefixer. These allow you to use tailwind's classnames for your styling.

Next in your tailwind.config.js, add all these paths to your tailwind template file.

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
Enter fullscreen mode Exit fullscreen mode

Last step is to add these directives in your main CSS files (usually it's in './src/index.css'):

@tailwind base;
@tailwind components;
@tailwind utilities;
Enter fullscreen mode Exit fullscreen mode

And that's it! Tailwind is installed. Let's go through some examples in how to implement this styling framework...

Top comments (0)