Using Tailwind With Vite

Published Oct 3, 2021

Table of Contents

Initialize the Project

Initialize the Vite project.

npm init vite@latest

Install dependencies.

npm i

Install Tailwind

Vite has PostCSS and Autoprefixer built-in, so there’s no need to install it.

npm i -D tailwindcss@latest

Initialize the Tailwind Config

Depending on your project and folder structure be sure to include what files to purge to optimize for production.

npx tailwindcss init -p

I like to enable JIT (Just-in-Time Mode) inside the Tailwind config that enables lightning fast build times and having every variant enabled out of the box. If you want to learn more about it watch Just-In-Time: The Next Generation of Tailwind CSS.

module.exports = {
  mode: 'jit',
  purge: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
  darkMode: false,
  theme: {
    extend: {},
  variants: {
    extend: {},
  plugins: [],

Add @tailwind Directives

Add this to your styles.

@tailwind base;
@tailwind components;
@tailwind utilities;

Import Styles

Import your styles.

import './tailwind.css'


If you’re using Visual Studio Code I highly recommend to get these extensions, or look if they exist for your editor.


Setting up Tailwind with Vite is simple. Hope you found it useful and I wish you good luck in your project.

Thanks for reading! πŸ„β€β™€οΈ


If you want to support the content you're reading or watching on YouTube consider becoming a patreon starting low as 1$ per month.

Become a patreon
Subscribe For Updates
Found a mistake?

Every post is a Markdown file so contributing is simple as following the link below and pressing the pencil icon inside GitHub to edit it.

Edit on GitHub