- What is Tailwind CSS?
- Setting Up Tailwind CSS
- Using Tailwind CSS with React
- Using Tailwind CSS with Vue.js
- Using Tailwind CSS with Angular
- Advanced Tailwind CSS Techniques
- Real-World Example: Building a Dashboard
- Using Tailwind CSS with Svelte
- Using Tailwind CSS with Next.js
- Using Tailwind CSS with Nuxt.js
- Using Tailwind CSS with Ember.js
- Conclusion
Tailwind CSS is a utility-first CSS framework that has gained immense popularity among developers for its simplicity and flexibility. It allows you to build modern, responsive designs directly in your HTML by applying utility classes. When combined with JavaScript frameworks like React, Vue, and Angular, Tailwind CSS can significantly speed up your development process and improve the maintainability of your code. This comprehensive guide will show you how to use Tailwind CSS with popular JavaScript frameworks, covering everything from setup to advanced usage.
What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that provides low-level utility classes to build custom designs without leaving your HTML. Instead of writing custom CSS for each component, you apply utility classes directly to your elements, making it easy to see the styles applied to your HTML.
For example, instead of writing a CSS class for a button, you can directly use utility classes in your HTML:
<button class="bg-blue-500 text-white py-2 px-4 rounded">
Button
</button>
This approach keeps your CSS minimal and makes it easier to maintain and understand your styles.
Setting Up Tailwind CSS
To get started with Tailwind CSS, you need to install it in your project. Tailwind CSS can be installed via npm, and it requires Node.js and npm to be installed on your machine.
Installing Tailwind CSS
First, create a new project or navigate to your existing project directory. Then, install Tailwind CSS and its peer dependencies:
npm install tailwindcss postcss autoprefixer
Next, initialize Tailwind CSS to create the tailwind.config.js
and postcss.config.js
files:
npx tailwindcss init -p
This command creates a default configuration file for Tailwind CSS and a PostCSS configuration file.
Configuring Tailwind CSS
Open the tailwind.config.js
file and configure the content paths to include all the files where you will be using Tailwind CSS classes:
module.exports = {
content: [
'./src/**/*.{html,js,jsx,ts,tsx,vue}',
],
theme: {
extend: {},
},
plugins: [],
}
This configuration ensures that Tailwind CSS scans the specified files for class names and includes only the necessary styles in the final CSS file.
Adding Tailwind CSS to Your Styles
Create a CSS file in your project, for example, src/styles/tailwind.css
, and add the following lines:
@tailwind base;
@tailwind components;
@tailwind utilities;
These directives import Tailwind CSS’s base styles, component styles, and utility classes.
Building Tailwind CSS
To build the final CSS file, you need to use a build tool like PostCSS. Add a script to your package.json
to run the build process:
"scripts": {
"build:css": "postcss src/styles/tailwind.css -o public/styles.css"
}
Run the build script to generate the final CSS file:
npm run build:css
This command processes the tailwind.css
file and outputs the final CSS file in the public
directory.
Using Tailwind CSS with React

React is one of the most popular JavaScript frameworks, and Tailwind CSS works seamlessly with it. Let’s see how to set up and use Tailwind CSS in a React project.
Setting Up a React Project
If you don’t have a React project set up, you can create one using Create React App:
npx create-react-app my-react-app
cd my-react-app
Follow the steps outlined in the previous section to install and configure Tailwind CSS in your React project.
Using Tailwind CSS in React Components
With Tailwind CSS set up, you can now use its utility classes in your React components. Open a component file, for example, src/App.js
, and start applying Tailwind CSS classes:
function App() {
return (
<div className="bg-gray-100 min-h-screen flex items-center justify-center">
<div className="bg-white p-6 rounded shadow-md">
<h1 className="text-2xl font-bold mb-4">Welcome to My React App</h1>
<button className="bg-blue-500 text-white py-2 px-4 rounded">
Click Me
</button>
</div>
</div>
);
}
export default App;
In this example, utility classes from Tailwind CSS are used to style the div
and button
elements. This approach keeps your styles clean and easy to manage directly within your components.
Handling Responsive Design
Tailwind CSS makes it easy to create responsive designs using its responsive utility classes. You can apply different styles based on the screen size by using prefixes like sm:
, md:
, lg:
, and xl:
.
For example, to create a responsive button, you can apply different padding and font sizes for different screen sizes:
<button className="bg-blue-500 text-white py-2 px-4 rounded sm:py-3 sm:px-5 md:py-4 md:px-6 lg:py-5 lg:px-7">
Responsive Button
</button>
This button will have different padding and font sizes on small, medium, and large screens, ensuring a consistent and responsive design.
Using Tailwind CSS with Vue.js

Vue.js is another popular JavaScript framework known for its simplicity and flexibility. Tailwind CSS integrates smoothly with Vue.js, allowing you to build stylish and responsive UIs efficiently.
Setting Up a Vue.js Project
If you don’t have a Vue.js project set up, you can create one using Vue CLI:
npm install -g @vue/cli
vue create my-vue-app
cd my-vue-app
Follow the steps outlined in the Tailwind CSS setup section to install and configure Tailwind CSS in your Vue.js project.
Using Tailwind CSS in Vue Components
With Tailwind CSS set up, you can now use its utility classes in your Vue components. Open a component file, for example, src/components/HelloWorld.vue
, and start applying Tailwind CSS classes:
<template>
<div class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="bg-white p-6 rounded shadow-md">
<h1 class="text-2xl font-bold mb-4">Welcome to My Vue App</h1>
<button class="bg-blue-500 text-white py-2 px-4 rounded">
Click Me
</button>
</div>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
};
</script>
In this example, utility classes from Tailwind CSS are used to style the div
and button
elements within the Vue component.
Handling Responsive Design
Tailwind CSS makes it easy to create responsive designs in Vue components using its responsive utility classes. You can apply different styles based on the screen size by using prefixes like sm:
, md:
, lg:
, and xl:
.
For example, to create a responsive button, you can apply different padding and font sizes for different screen sizes:
<template>
<button class="bg-blue-500 text-white py-2 px-4 rounded sm:py-3 sm:px-5 md:py-4 md:px-6 lg:py-5 lg:px-7">
Responsive Button
</button>
</template>
This button will have different padding and font sizes on small, medium, and large screens, ensuring a consistent and responsive design.
Using Tailwind CSS with Angular

Angular is a robust JavaScript framework for building large-scale applications. Tailwind CSS can be integrated with Angular to help you build responsive and modern UIs efficiently.
Setting Up an Angular Project
If you don’t have an Angular project set up, you can create one using Angular CLI:
npm install -g @angular/cli
ng new my-angular-app
cd my-angular-app
Follow the steps outlined in the Tailwind CSS setup section to install and configure Tailwind CSS in your Angular project.
Using Tailwind CSS in Angular Components
With Tailwind CSS set up, you can now use its utility classes in your Angular components. Open a component file, for example, src/app/app.component.html
, and start applying Tailwind CSS classes:
<div class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="bg-white p-6 rounded shadow-md">
<h1 class="text-2xl font-bold mb-4">Welcome to My Angular App</h1>
<button class="bg-blue-500 text-white py-2 px-4 rounded">
Click Me
</button>
</div>
</div>
In this example, utility classes from Tailwind CSS are used to style the div
and button
elements within the Angular component.
Handling Responsive Design
Tailwind CSS makes it easy to create responsive designs in Angular components using its responsive utility classes. You can apply different styles based on the screen size by using prefixes like sm:
, md:
, lg:
, and xl:
.
For example, to create a responsive button, you can apply different padding and font sizes for different screen sizes:
<button class="bg-blue-500 text-white py-2 px-4 rounded sm:py-3 sm:px-5 md:py-4 md:px-6 lg:py-5 lg:px-7">
Responsive Button
</button>
This button will have different padding and font sizes on small, medium, and large screens, ensuring a consistent and responsive design.
Advanced Tailwind CSS Techniques
Beyond the basics, Tailwind CSS offers several advanced techniques that can further enhance your development workflow and help you create even more powerful designs.
Customizing Tailwind CSS
Tailwind CSS is highly customizable. You can extend its default configuration to add custom colors, fonts, spacing, and more. To customize Tailwind CSS, modify the tailwind.config.js
file.
For example, to add custom colors and spacing, you can update the configuration like this:
module.exports = {
content: ['./src/**/*.{html,js,jsx,ts,tsx,vue}'],
theme: {
extend: {
colors: {
'custom-blue': '#1DA1F2',
'custom-green': '#17BF63',
},
spacing: {
'72': '18rem',
'84': '21rem',
'96': '24rem',
},
},
},
plugins: [],
};
This configuration adds custom blue and green colors and additional spacing utilities to your project.
Using Plugins
Tailwind CSS has a rich ecosystem of plugins that can extend its functionality. These plugins can add new utilities, components, or even entire design systems. To use a plugin, you need to install it and add it to your Tailwind CSS configuration.
For example, to use the @tailwindcss/forms
plugin to style form elements, you can install it and update your configuration:
npm install @tailwindcss/forms
// tailwind.config.js
module.exports = {
content: ['./src/**/*.{html,js,jsx,ts,tsx,vue}'],
theme: {
extend: {},
},
plugins: [
require('@tailwindcss/forms'),
],
};
This plugin provides a set of form styles that are more consistent and easier to customize.
Purging Unused CSS
One of the most significant advantages of Tailwind CSS is its ability to remove unused CSS, resulting in smaller file sizes and improved performance. Tailwind CSS comes with a built-in purge tool that scans your content files and removes unused styles.
Ensure your tailwind.config.js
is set up to include all relevant content files:
module.exports = {
content: ['./src/**/*.{html,js,jsx,ts,tsx,vue}'],
theme: {
extend: {},
},
plugins: [],
};
When you build your project for production, Tailwind CSS will automatically purge unused styles, keeping your final CSS file as small as possible.
Real-World Example: Building a Dashboard
To see Tailwind CSS in action with a JavaScript framework, let’s build a simple dashboard using React and Tailwind CSS. This dashboard will include a sidebar, a header, and a content area with cards.
Setting Up the Project
Create a new React project and set up Tailwind CSS as described earlier. Ensure you have the necessary files and configurations in place.
Creating the Sidebar
Create a Sidebar.js
component to hold the sidebar navigation:
// src/components/Sidebar.js
import React from 'react';
const Sidebar = () => (
<div className="bg-gray-800 text-white h-screen w-64 p-4">
<h2 className="text-2xl font-bold mb-6">Dashboard</h2>
<nav>
<a href="#" className="block py-2 px-4 rounded hover:bg-gray-700">
Home
</a>
<a href="#" className="block py-2 px-4 rounded hover:bg-gray-700">
Settings
</a>
<a href="#" className="block py-2 px-4 rounded hover:bg-gray-700">
Profile
</a>
</nav>
</div>
);
export default Sidebar;
Creating the Header
Create a Header.js
component for the header:
// src/components/Header.js
import React from 'react';
const Header = () => (
<div className="bg-white shadow p-4">
<h1 className="text-2xl font-bold">Dashboard</h1>
</div>
);
export default Header;
Creating the Dashboard Content
Create a Dashboard.js
component for the main content area:
// src/components/Dashboard.js
import React from 'react';
const Dashboard = () => (
<div className="p-4">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<div className="bg-white p-6 rounded shadow-md">
<h2 className="text-xl font-bold mb-2">Card 1</h2>
<p>Content for card 1 goes here.</p>
</div>
<div className="bg-white p-6 rounded shadow-md">
<h2 className="text-xl font-bold mb-2">Card 2</h2>
<p>Content for card 2 goes here.</p>
</div>
<div className="bg-white p-6 rounded shadow-md">
<h2 className="text-xl font-bold mb-2">Card 3</h2>
<p>
Content for card 3 goes here.</p>
</div>
</div>
</div>
);
export default Dashboard;
Assembling the Dashboard
Combine these components in the App.js
file:
// src/App.js
import React from 'react';
import Sidebar from './components/Sidebar';
import Header from './components/Header';
import Dashboard from './components/Dashboard';
function App() {
return (
<div className="flex">
<Sidebar />
<div className="flex-1 flex flex-col">
<Header />
<Dashboard />
</div>
</div>
);
}
export default App;
In this example, the App
component renders the Sidebar
, Header
, and Dashboard
components to create a simple dashboard layout. Tailwind CSS utility classes are used throughout to style the elements.
Using Tailwind CSS with Svelte

Svelte is a modern JavaScript framework that compiles components to highly efficient vanilla JavaScript. Integrating Tailwind CSS with Svelte can help you build stylish, performant applications with ease.
Setting Up a Svelte Project
To get started with Svelte, you can create a new project using the Svelte template:
npx degit sveltejs/template my-svelte-app
cd my-svelte-app
npm install
Follow the steps outlined in the Tailwind CSS setup section to install and configure Tailwind CSS in your Svelte project.
Using Tailwind CSS in Svelte Components
With Tailwind CSS set up, you can now use its utility classes in your Svelte components. Open a component file, for example, src/App.svelte
, and start applying Tailwind CSS classes:
<script>
export let name = 'world';
</script>
<style>
main {
text-align: center;
padding: 1em;
max-width: 240px;
margin: 0 auto;
}
</style>
<main class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="bg-white p-6 rounded shadow-md">
<h1 class="text-2xl font-bold mb-4">Hello {name}!</h1>
<button class="bg-blue-500 text-white py-2 px-4 rounded">
Click Me
</button>
</div>
</main>
In this example, utility classes from Tailwind CSS are used to style the div
and button
elements within the Svelte component.
Handling Responsive Design
Tailwind CSS makes it easy to create responsive designs in Svelte components using its responsive utility classes. You can apply different styles based on the screen size by using prefixes like sm:
, md:
, lg:
, and xl:
.
For example, to create a responsive button, you can apply different padding and font sizes for different screen sizes:
<button class="bg-blue-500 text-white py-2 px-4 rounded sm:py-3 sm:px-5 md:py-4 md:px-6 lg:py-5 lg:px-7">
Responsive Button
</button>
This button will have different padding and font sizes on small, medium, and large screens, ensuring a consistent and responsive design.
Using Tailwind CSS with Next.js

Next.js is a React framework that provides server-side rendering and static site generation capabilities. Combining Tailwind CSS with Next.js can help you build fast, scalable, and stylish applications.
Setting Up a Next.js Project
To get started with Next.js, you can create a new project using the Create Next App command:
npx create-next-app my-next-app
cd my-next-app
Follow the steps outlined in the Tailwind CSS setup section to install and configure Tailwind CSS in your Next.js project.
Using Tailwind CSS in Next.js Pages and Components
With Tailwind CSS set up, you can now use its utility classes in your Next.js pages and components. Open a page file, for example, pages/index.js
, and start applying Tailwind CSS classes:
function HomePage() {
return (
<div className="bg-gray-100 min-h-screen flex items-center justify-center">
<div className="bg-white p-6 rounded shadow-md">
<h1 className="text-2xl font-bold mb-4">Welcome to My Next.js App</h1>
<button className="bg-blue-500 text-white py-2 px-4 rounded">
Click Me
</button>
</div>
</div>
);
}
export default HomePage;
In this example, utility classes from Tailwind CSS are used to style the div
and button
elements within the Next.js page.
Handling Responsive Design
Tailwind CSS makes it easy to create responsive designs in Next.js using its responsive utility classes. You can apply different styles based on the screen size by using prefixes like sm:
, md:
, lg:
, and xl:
.
For example, to create a responsive button, you can apply different padding and font sizes for different screen sizes:
<button className="bg-blue-500 text-white py-2 px-4 rounded sm:py-3 sm:px-5 md:py-4 md:px-6 lg:py-5 lg:px-7">
Responsive Button
</button>
This button will have different padding and font sizes on small, medium, and large screens, ensuring a consistent and responsive design.
Using Tailwind CSS with Nuxt.js

Nuxt.js is a powerful Vue.js framework for building server-side rendered applications. Integrating Tailwind CSS with Nuxt.js can help you create performant and stylish applications effortlessly.
Setting Up a Nuxt.js Project
To get started with Nuxt.js, you can create a new project using the Create Nuxt App command:
npx create-nuxt-app my-nuxt-app
cd my-nuxt-app
Follow the steps outlined in the Tailwind CSS setup section to install and configure Tailwind CSS in your Nuxt.js project.
Using Tailwind CSS in Nuxt.js Pages and Components
With Tailwind CSS set up, you can now use its utility classes in your Nuxt.js pages and components. Open a page file, for example, pages/index.vue
, and start applying Tailwind CSS classes:
<template>
<div class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="bg-white p-6 rounded shadow-md">
<h1 class="text-2xl font-bold mb-4">Welcome to My Nuxt.js App</h1>
<button class="bg-blue-500 text-white py-2 px-4 rounded">
Click Me
</button>
</div>
</div>
</template>
<script>
export default {
name: 'HomePage',
};
</script>
In this example, utility classes from Tailwind CSS are used to style the div
and button
elements within the Nuxt.js page.
Handling Responsive Design
Tailwind CSS makes it easy to create responsive designs in Nuxt.js using its responsive utility classes. You can apply different styles based on the screen size by using prefixes like sm:
, md:
, lg:
, and xl:
.
For example, to create a responsive button, you can apply different padding and font sizes for different screen sizes:
<button class="bg-blue-500 text-white py-2 px-4 rounded sm:py-3 sm:px-5 md:py-4 md:px-6 lg:py-5 lg:px-7">
Responsive Button
</button>
This button will have different padding and font sizes on small, medium, and large screens, ensuring a consistent and responsive design.
Using Tailwind CSS with Ember.js

Ember.js is a powerful framework for building ambitious web applications. Integrating Tailwind CSS with Ember.js can enhance your development workflow by providing a robust and flexible styling solution.
Setting Up an Ember.js Project
To get started with Ember.js, you can create a new project using the Ember CLI:
npm install -g ember-cli
ember new my-ember-app
cd my-ember-app
Follow the steps outlined in the Tailwind CSS setup section to install and configure Tailwind CSS in your Ember.js project.
Using Tailwind CSS in Ember Components
With Tailwind CSS set up, you can now use its utility classes in your Ember components. Open a component file, for example, app/components/hello-world.hbs
, and start applying Tailwind CSS classes:
<div class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="bg-white p-6 rounded shadow-md">
<h1 class="text-2xl font-bold mb-4">Welcome to My Ember App</h1>
<button class="bg-blue-500 text-white py-2 px-4 rounded">
Click Me
</button>
</div>
</div>
In this example, utility classes from Tailwind CSS are used to style the div
and button
elements within the Ember component.
Handling Responsive Design
Tailwind CSS makes it easy to create responsive designs in Ember.js using its responsive utility classes. You can apply different styles based on the screen size by using prefixes like sm:
, md:
, lg:
, and xl:
.
For example, to create a responsive button, you can apply different padding and font sizes for different screen sizes:
<button class="bg-blue-500 text-white py-2 px-4 rounded sm:py-3 sm:px-5 md:py-4 md:px-6 lg:py-5 lg:px-7">
Responsive Button
</button>
This button will have different padding and font sizes on small, medium, and large screens, ensuring a consistent and responsive design.
Conclusion
Using Tailwind CSS with various JavaScript frameworks can significantly streamline your development process, allowing you to build stylish, responsive, and maintainable applications. Whether you are working with React, Vue.js, Angular, Svelte, Next.js, Nuxt.js, or Ember.js, Tailwind CSS provides a robust and flexible styling solution that can enhance your workflow and improve the overall quality of your projects.
By following the steps outlined in this guide, you can effectively integrate Tailwind CSS into your projects and leverage its powerful features to create beautiful and performant web applications. As you continue to explore and use Tailwind CSS, you’ll find that it offers an intuitive and efficient way to manage your styles, making your development experience more enjoyable and productive.
Read Next: