Quickstart Guide
Get up and running with Tailwind CSS in just a few minutes. This guide will walk you through creating a new project, installing Tailwind, and building your first component.This guide covers Tailwind CSS v4.2.1. If you’re upgrading from v3, check out the migration guide.
Quick Start with Vite + React
The fastest way to get started with Tailwind CSS is using Vite with React. Follow these steps to create a new project from scratch.1
Create a new Vite project
Use your preferred package manager to scaffold a new Vite + React project:
2
Install Tailwind CSS and the Vite plugin
Install Tailwind CSS and the official Vite plugin:
3
Configure Vite
Add the Tailwind CSS plugin to your
vite.config.ts or vite.config.js:vite.config.ts
4
Import Tailwind in your CSS
Create or update your main CSS file (e.g., Then import this CSS file in your main entry point:
src/index.css) to import Tailwind:src/index.css
src/main.tsx
5
Start building
Run the development server and start using Tailwind’s utility classes:Your project is now set up with Tailwind CSS! Continue reading to learn how to build your first component.
Building Your First Component
Let’s build a beautiful card component using Tailwind’s utility classes. This example demonstrates the power of utility-first CSS.Simple Card Component
Here’s a complete card component with an image, title, description, and button:src/App.tsx
Understanding the Utilities
Let’s break down what each utility class does:- Layout
- Card Container
- Image
- Typography
min-h-screen- Minimum height of 100vhbg-gray-50- Light gray background colorflex- Display as flexboxitems-center- Center items verticallyjustify-center- Center items horizontallyp-4- Padding of 1rem (16px) on all sides
Responsive Design
Make your card responsive across different screen sizes using Tailwind’s breakpoint system:Tailwind uses a mobile-first approach. Unprefixed utilities apply to all screen sizes, while prefixed utilities (like
md: and lg:) apply at the specified breakpoint and above.Breakpoint Reference
Hover, Focus, and Other States
Tailwind makes it easy to style interactive states using variant prefixes:Common State Variants
hover:- Style on mouse hoverfocus:- Style when element has focusactive:- Style when element is being clickeddisabled:- Style when element is disabledgroup-hover:- Style based on parent hover statedark:- Style in dark mode
Common Utility Patterns
Here are some frequently used utility combinations:Quick Start with Next.js
If you prefer Next.js, here’s how to set up Tailwind CSS:1
Create a Next.js project
2
Install dependencies
3
Configure PostCSS
Create a
postcss.config.js file in your project root:postcss.config.js
4
Import Tailwind CSS
Add Tailwind to your global CSS file (e.g.,
app/globals.css):app/globals.css
5
Start building
Customizing Your Setup
Adding Custom Colors
Define custom colors using CSS variables in your main CSS file:src/index.css
Creating Reusable Components
Use@layer to add custom component styles:
src/index.css
Production Optimization
Tailwind CSS v4 automatically optimizes your CSS for production. Here are some tips to maximize performance:1. Enable Minification
The Vite plugin automatically minifies in production, but you can configure it:vite.config.ts
2. Limit Source Scanning
Use the@source directive to limit which files Tailwind scans:
src/index.css
3. Remove Unused Styles
Tailwind v4 uses the Oxide engine to automatically detect and remove unused CSS. Just ensure your build process is set up correctly.4. Enable Source Maps
For debugging production issues:vite.config.ts
Next Steps
Now that you’ve built your first Tailwind CSS project, explore more advanced features:Core Concepts
Deep dive into utility-first CSS and Tailwind’s philosophy
Responsive Design
Master responsive layouts with Tailwind’s breakpoint system
Dark Mode
Implement dark mode with a single class prefix
Customization
Customize your theme with colors, spacing, and more
Editor Setup
Configure IntelliSense for autocomplete and linting
Adding Custom Styles
Learn when and how to add custom CSS to your Tailwind project
Common Issues
Styles Not Applying
If your styles aren’t working:- Ensure you’ve imported Tailwind CSS in your main CSS file
- Check that your CSS file is imported in your main entry point
- Verify the Vite plugin is configured correctly
- Restart your development server
IntelliSense Not Working
For better autocomplete:- Install the Tailwind CSS IntelliSense extension
- Configure your editor following the editor setup guide
Build Performance
For faster builds:- Limit source file scanning with
@sourcedirectives - Use the Oxide engine (included by default in v4)
- Only optimize CSS in production builds
Need more help? Check out our installation guide for detailed setup instructions or join the Tailwind CSS Discord community.