2HAASStart a project
All posts

Guides

Mastering Tailwind CSS v4 Configuration and Setup

Learn how to set up and configure Tailwind CSS v4 using the new CSS-first approach for faster builds and cleaner project structures.

The 2HAAS team2 min read

Building modern web applications requires fast tooling and clean configuration setups. Traditional styling methods often lead to bloated stylesheets and confusing configuration files that slow down your development process. Tailwind CSS v4 addresses these pain points with a completely reimagined architecture built for speed and simplicity.

Understanding the CSS First Approach

Previous versions of Tailwind relied heavily on a JavaScript configuration file named tailwind.config.js to extend themes and manage variants. Version 4 shifts this responsibility entirely to standard CSS. You now configure your design tokens, custom fonts, and color palettes directly within your main stylesheet using the new @theme directive.

This change aligns the framework with native CSS specifications and eliminates the need to jump between JavaScript and CSS files during styling tasks. The underlying engine also receives a massive performance upgrade, utilizing Rust-based compilation that runs up to ten times faster than older versions.

Step by Step Installation Guide

Getting started with the new version requires just a few commands in your terminal. Follow these steps to set up the framework in a standard project.

  1. Initialize your project directory and install the necessary package using your preferred package manager.
  2. Create a source directory for your CSS files and a public directory for your HTML markup.
  3. Import the framework into your main stylesheet and define your custom theme variables.

Here is the exact command to install the package:

npm install tailwindcss @tailwindcss/cli

Create your main CSS file, typically located at src/input.css, and add the base import directive:

@import "tailwindcss";

@theme {
  --color-brand-primary: #cc3f0c;
  --color-brand-light: #fffafa;
  --color-brand-dark: #1a1a1a;
}

Compiling Styles for Production

To compile your styles during development, use the new CLI tool provided by the framework. Run the build command and point it to your input and output files.

npx @tailwindcss/cli -i ./src/input.css -o ./src/output.css --watch

Key Differences Between Versions

Feature Tailwind CSS v3 Tailwind CSS v4
Configuration JavaScript File CSS-First Directives
Engine JavaScript Compiler Rust-Powered Engine
Import Syntax @tailwind directives Standard @import
Container Queries Requires Plugin Built-in Native Support

Summary and Checklist

Adopting Tailwind CSS v4 modernizes your frontend workflow and drastically reduces build times. Review this checklist before launching your upgrade:

  • Remove legacy JavaScript configuration files if migrating an existing project.
  • Update your CSS imports to use the new standard syntax.
  • Test all custom theme extensions inside the @theme block.
  • Verify your build pipeline integrates the updated CLI command.

Keep reading

  1. Guides4 min read

    Mastering Responsive Layouts with CSS Container Queries

    Learn how to implement CSS Container Queries for truly responsive, component-based layouts. This guide covers setup, syntax, and practical examples.

  2. Guides5 min read

    Build Offline Web Apps with Service Workers

    Discover how to use Service Workers to make your web applications work offline. Learn caching strategies and PWA principles.

  3. Guides5 min read

    Guide to Implementing Web Push Notifications

    Learn how to set up and send web push notifications to re-engage users. This guide covers client-side setup and server-side logic.

Tell us what’s in the way.

A few lines is enough. You get a candid yes, a candid no, or a sharper question.

  • Working software in week four
  • A reply in one business day
  • Handover is the deliverable

Prefer email? [email protected]

The problem, who it is for, and what is in the way right now.

One business day to a real reply. No sales sequence, no call required.