To use Tailwind CSS in Replit, install tailwindcss and the PostCSS CLI via the Shell tab, create tailwind.config.js and postcss.config.js, and add a build script to your package.json that compiles your CSS. Replit's live preview updates immediately when the CSS rebuilds. JIT mode is enabled by default in Tailwind v3 and v4 — you get only the classes your HTML uses, keeping the bundle tiny.
Configuring Tailwind CSS in Replit
Tailwind CSS is the most popular utility-first CSS framework, used across millions of projects from static sites to full-stack applications. Unlike traditional CSS frameworks that give you pre-built components, Tailwind gives you low-level utility classes — text-blue-500, flex, rounded-lg, p-4 — that you compose directly in HTML markup. This approach eliminates the need to write custom CSS for most styling tasks and keeps your styles co-located with your markup.
In Replit, Tailwind is set up as a build step rather than a CDN import. The build step is important because Tailwind's JIT (Just-In-Time) engine scans your HTML and JavaScript files to determine which utility classes you actually use, then generates a minimal CSS output file containing only those classes. This keeps the generated CSS tiny even though the full Tailwind library has thousands of classes. A CDN version of Tailwind works for quick prototyping but should not be used in production because it loads the entire unoptimized stylesheet.
Tailwind v3 uses a JavaScript configuration file (tailwind.config.js) and PostCSS for processing. Tailwind v4 (released in early 2025) shifts to a CSS-first approach — configuration lives directly in your main CSS file using CSS custom properties, with no JavaScript config file required. Both versions work in Replit. This guide covers v3 primarily (the most widely deployed) with v4 notes where they differ significantly.
Integration method
Tailwind CSS integrates with Replit as a PostCSS build step. You install Tailwind and PostCSS via npm, initialize the configuration files, and run a build watcher that compiles your Tailwind CSS file into a standard output CSS file. The output CSS is referenced by your HTML. Replit's live preview reflects changes immediately when the watcher rebuilds. Tailwind v3 and v4 both work on Replit — v3 uses traditional PostCSS configuration, v4 is CSS-first with no JavaScript config file.
Prerequisites
- A Replit account with a Node.js Repl (Tailwind requires a Node.js build step)
- Basic familiarity with HTML and CSS
- Understanding that Tailwind needs a build step — it is not just a CDN link
Step-by-step guide
Install Tailwind CSS and PostCSS
Install Tailwind CSS and PostCSS
Open the Shell tab in your Replit project and run the installation command. Tailwind CSS requires PostCSS as its CSS processing engine and autoprefixer for cross-browser compatibility. For Tailwind v3 (current stable): npm install -D tailwindcss postcss autoprefixer For Tailwind v4 (if you want the latest): npm install -D tailwindcss@next @tailwindcss/postcss@next After installing, initialize the Tailwind configuration files. For v3, run: npx tailwindcss init -p. This generates two files: tailwind.config.js (Tailwind's settings) and postcss.config.js (PostCSS pipeline configuration). For Tailwind v4, configuration lives in CSS — skip the init command and instead add @import 'tailwindcss' to your main CSS file and configure via CSS custom properties. The -D flag (devDependency) is correct — Tailwind is a build-time tool, not a runtime dependency. It processes your CSS during development and build, producing a plain CSS output file that is the only thing deployed. Verify installation by checking your package.json — tailwindcss, postcss, and autoprefixer should appear in devDependencies. You can also run npx tailwindcss --version to confirm the installed version.
1# Install Tailwind CSS v3 with PostCSS and Autoprefixer2npm install -D tailwindcss postcss autoprefixer34# Initialize config files (creates tailwind.config.js and postcss.config.js)5npx tailwindcss init -p67# Verify installation8npx tailwindcss --versionPro tip: If you are adding Tailwind to an existing React or Vite project in Replit, check if it already has tailwindcss in its devDependencies before installing. Vite + React templates from Replit often have Tailwind pre-configured — run npx tailwindcss --version first.
Expected result: tailwindcss, postcss, and autoprefixer appear in package.json devDependencies. tailwind.config.js and postcss.config.js files exist in the project root.
Configure tailwind.config.js Content Paths
Configure tailwind.config.js Content Paths
Open tailwind.config.js. The most critical configuration is the content array — this tells Tailwind's JIT engine which files to scan for class names. Without correct content paths, Tailwind generates an empty CSS file because it finds no used classes. The content array uses glob patterns. For a standard Express project with HTML templates in a views/ folder and JavaScript in public/: include './views/**/*.{html,ejs}' and './public/**/*.js'. For a static HTML site: './src/**/*.html'. For a React project: './src/**/*.{js,jsx,ts,tsx}'. Also create your main CSS input file. Create a file at src/input.css (or your preferred path) with the three Tailwind directives. These directives are processed by PostCSS and replaced with Tailwind's generated CSS: @tailwind base — Preflight CSS reset and base styles. @tailwind components — Any custom component classes you define. @tailwind utilities — All the utility classes Tailwind generates. The postcss.config.js generated by the init command is already correct — it includes tailwindcss and autoprefixer as PostCSS plugins. You typically do not need to edit it. The theme.extend section in tailwind.config.js is where you add custom design tokens without replacing Tailwind's defaults. Add custom colors, fonts, and spacing here. Using extend preserves all of Tailwind's default utilities while adding your custom ones.
1// tailwind.config.js — Tailwind v3 configuration2/** @type {import('tailwindcss').Config} */3module.exports = {4 content: [5 './src/**/*.{html,js,ts,jsx,tsx}',6 './views/**/*.{html,ejs,pug}',7 './public/**/*.{html,js}',8 // Add any other paths where you use Tailwind classes9 ],10 theme: {11 extend: {12 // Add custom design tokens here without overriding defaults13 colors: {14 brand: {15 50: '#eff6ff',16 500: '#3b82f6',17 900: '#1e3a8a'18 }19 },20 fontFamily: {21 sans: ['Inter', 'system-ui', 'sans-serif']22 }23 }24 },25 plugins: []26};Pro tip: If Tailwind utilities appear in Replit's editor but do not render in the browser preview, the content path is wrong. Open the generated output CSS file — if it is nearly empty (only base styles, no utilities), the content scan found no class usage. Double-check your glob patterns match where your HTML/JS files actually live.
Expected result: tailwind.config.js has correct content paths pointing to your HTML and JavaScript files. src/input.css contains the three @tailwind directives.
Create Input CSS and Run the Build Watcher
Create Input CSS and Run the Build Watcher
Create your Tailwind input CSS file. This is the source file that PostCSS processes — it contains the @tailwind directives and any custom CSS you write. Create src/input.css with the three Tailwind directives and any custom CSS you want alongside Tailwind's generated utilities. Add build scripts to package.json. You need two scripts: one that builds the CSS once for production, and one that watches for changes during development and rebuilds automatically. For the build watch script, you can use tailwindcss --watch or the PostCSS CLI. The --watch flag tells Tailwind to watch your input files and content paths, rebuilding the output CSS whenever anything changes. For a Replit development workflow with a Node.js server, you typically want to run both the CSS watcher and your server concurrently. Install concurrently: npm install -D concurrently. Then add a dev script that runs both processes simultaneously. Configure your .replit file so the Run button starts the dev script. Edit the run command in the .replit file to call npm run dev. After starting the watcher, link the compiled output CSS in your HTML. Add a <link> tag pointing to your output CSS file (e.g., /styles/output.css). Start using Tailwind classes in your HTML — they will compile into the output CSS automatically. For Tailwind v4, the CSS-first configuration looks different. Add @import 'tailwindcss' at the top of your CSS file, and define theme variables with @theme { --color-brand: #3b82f6; }. The processing is the same but the config format is simpler.
1/* src/input.css — Tailwind CSS input file */2@tailwind base;3@tailwind components;4@tailwind utilities;56/* Custom component classes using @layer */7@layer components {8 .btn-primary {9 @apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded;10 }11 .card {12 @apply bg-white rounded-lg shadow-md p-6;13 }14}1516/* Custom utilities */17@layer utilities {18 .text-balance {19 text-wrap: balance;20 }21}Pro tip: The @layer directive in Tailwind lets you define custom CSS that participates in Tailwind's purging — classes defined in @layer components are only included in the output if they are used in your content files. This keeps your custom CSS bundle-safe.
Expected result: Running npm run dev starts both the Tailwind watcher and your server. Editing HTML files with Tailwind classes triggers a CSS rebuild. The browser preview shows styled content using Tailwind utilities.
Configure package.json Scripts and .replit
Configure package.json Scripts and .replit
Update package.json to add the necessary scripts for building and watching Tailwind CSS. The CSS output path (public/styles/output.css) should be in a publicly served directory for your web server. For the Run button in Replit to start your development server with the Tailwind watcher, update the .replit configuration file. The run command should call npm run dev, which starts both processes concurrently. With Autoscale deployments on Replit, the build step should generate the production CSS before the server starts. Add a postinstall script or a build script that generates the production output, and configure the deployment run command to build CSS before starting the server. For production deployments, always generate CSS with the production build command (no --watch flag) to ensure the final CSS is optimized and minified. Tailwind v3 adds minification when NODE_ENV=production is set.
1// package.json scripts section2{3 "scripts": {4 "build:css": "tailwindcss -i ./src/input.css -o ./public/styles/output.css --minify",5 "watch:css": "tailwindcss -i ./src/input.css -o ./public/styles/output.css --watch",6 "start": "node server.js",7 "dev": "concurrently \"npm run watch:css\" \"npm run start\""8 }9}1011// .replit file — configure Run button12// run = "npm run dev"13// [deployment]14// run = ["sh", "-c", "npm run build:css && node server.js"]1516// In HTML — link the compiled CSS17// <link rel="stylesheet" href="/styles/output.css">1819// Example HTML using Tailwind classes20// <div class="flex items-center justify-center min-h-screen bg-gray-50">21// <div class="bg-white rounded-2xl shadow-xl p-8 max-w-md w-full">22// <h1 class="text-2xl font-bold text-gray-900 mb-4">Hello Tailwind</h1>23// <p class="text-gray-600">Styled with utility classes, built in Replit.</p>24// <button class="btn-primary mt-4 w-full">Get Started</button>25// </div>26// </div>Pro tip: For Autoscale deployments, set the deployment run command to 'npm run build:css && node server.js' in the .replit file. This ensures the production CSS is compiled before the server starts serving requests.
Expected result: npm run dev starts the Tailwind watcher and server together. npm run build:css generates a minified production CSS file. The HTML renders with Tailwind styles in the Replit browser preview.
Common use cases
Express App with Tailwind UI
Add Tailwind CSS to an Express.js Replit project serving HTML templates. Run the Tailwind watcher as a concurrent process alongside Express so styles rebuild automatically when you edit templates. Server-rendered HTML uses Tailwind utility classes for rapid styling without writing any custom CSS.
Set up Tailwind CSS in this Express project: install tailwindcss, create config files, add a CSS watcher, and style the homepage with a responsive hero section using Tailwind utility classes.
Copy this prompt to try it in Replit
Static HTML Site with Tailwind
Build a static HTML website in Replit using Tailwind for all styling. Configure Tailwind to scan your HTML files, run the build watcher, and use Tailwind's responsive prefixes (sm:, md:, lg:) to create a mobile-first layout without writing a single line of custom CSS.
Create a landing page with a navigation bar, hero section, feature grid, and footer using only Tailwind CSS utility classes. Configure the Tailwind build to watch all HTML files in the project.
Copy this prompt to try it in Replit
Design System Customization
Extend Tailwind with your brand's design tokens — custom colors, fonts, spacing scale, and border radii — by editing tailwind.config.js. Create a consistent design system across your Replit app that uses your brand values through Tailwind's utility class naming convention.
Configure tailwind.config.js to add a custom color palette for brand colors, a custom font family, and extend the spacing scale with project-specific values.
Copy this prompt to try it in Replit
Troubleshooting
Tailwind classes appear in HTML but the page has no styles
Cause: The output CSS file is not linked in the HTML, or the output CSS file path is wrong and the build watcher is writing to a different location than where the HTML link tag points.
Solution: Check the <link> tag in your HTML — the href path must match exactly where tailwindcss writes the output file. If the watcher runs without errors but the CSS file is empty or missing, check that the -o output path in the script matches a directory that exists.
1<!-- Verify the link tag matches your output path -->2<link rel="stylesheet" href="/styles/output.css">34<!-- Check the output file exists and has content -->5<!-- In Shell: ls -la public/styles/ && head -5 public/styles/output.css -->Output CSS is empty or only contains base reset styles, no utility classes
Cause: The content array in tailwind.config.js does not match the actual paths of your HTML/JS files, so Tailwind scans no files and finds no used classes.
Solution: Verify the glob patterns in the content array resolve to actual files. In the Shell, run: find . -name '*.html' -not -path './node_modules/*' to see where your HTML files actually are. Update the content paths to match.
1// Check what files Tailwind's content glob matches2// In Shell:3// node -e "const g = require('glob'); console.log(g.sync('./src/**/*.{html,js}'))"4// The output should list your HTML and JS filesCustom @apply classes not working — error 'Cannot apply unknown utility class'
Cause: The @apply directive references a Tailwind class that is not in the configured content or does not exist in Tailwind v3's utility set.
Solution: Verify the class name is spelled correctly and exists in Tailwind v3 (check tailwindcss.com/docs). If using custom classes in @apply, ensure they are defined in @layer utilities before being applied. Note that @apply only works with classes that exist in Tailwind's stylesheet.
1/* Correct @apply usage — class must exist in Tailwind */2@layer components {3 .btn {4 @apply px-4 py-2 rounded font-medium; /* These all exist in Tailwind */5 }6}Tailwind watcher stops after Replit auto-sleeps or restarts
Cause: The Tailwind --watch process is stopped when Replit's development environment sleeps. When you return and run the project again, the watcher needs to be restarted.
Solution: This is expected in Replit's development environment. Press the Run button to restart both the server and Tailwind watcher together. For Autoscale deployments (always-on), the deployment uses the build:css script once, not the watcher — the built CSS is static and does not need a running watcher in production.
Best practices
- Configure the content array in tailwind.config.js to scan only your HTML and JavaScript files — do not include node_modules or CSS files in content paths
- Use @layer components for reusable multi-utility patterns like buttons and cards rather than repeating long class strings across your HTML
- Run the production build with NODE_ENV=production or the --minify flag to get optimized, purged CSS output for deployment
- Keep custom CSS minimal — if you find yourself writing a lot of custom CSS, there is likely a Tailwind utility or @apply pattern that solves the same problem
- Use Tailwind's theme.extend to add custom design tokens rather than overriding defaults — this preserves all of Tailwind's default utilities alongside your brand values
- For Replit Autoscale deployments, add npm run build:css to the deployment run command so CSS is compiled fresh with each deploy
- Use the Tailwind CSS IntelliSense browser extension or VS Code extension if editing Tailwind-based code locally — autocomplete for class names significantly speeds up development
- For Tailwind v4 projects, use the CSS-first @theme configuration block instead of tailwind.config.js — it is simpler and keeps all config in CSS
Alternatives
Figma generates design specifications and CSS values that you then implement with Tailwind — use them together for design-to-code workflows.
Framer exports animated component code that you can style further with Tailwind, while Framer itself uses a proprietary styling system.
WordPress themes can be built with Tailwind CSS using a PostCSS setup similar to this guide — Tailwind and WordPress are complementary tools for theme development.
Frequently asked questions
How do I install Tailwind CSS in Replit?
Open the Shell tab in Replit and run: npm install -D tailwindcss postcss autoprefixer. Then run: npx tailwindcss init -p to create the configuration files. Create a src/input.css file with the @tailwind directives, configure content paths in tailwind.config.js, and add a build script to package.json.
Does Tailwind CSS work with Replit?
Yes. Tailwind CSS works on Replit as a PostCSS build step in any Node.js project. Install it via npm in the Shell tab, configure tailwind.config.js, and run the CSS watcher alongside your development server. The Replit live preview updates whenever the watcher rebuilds the CSS.
Can I use the Tailwind CSS CDN in Replit instead of installing it?
Yes, the CDN works for quick prototyping: add <script src='https://cdn.tailwindcss.com'></script> to your HTML and use Tailwind classes immediately. However, the CDN loads the full Tailwind stylesheet (~3MB) without JIT optimization and is not recommended for production. Use the npm install + build step for any serious project.
Why is my output CSS empty even though I am using Tailwind classes?
The content array in tailwind.config.js does not include the paths where your HTML/JavaScript files are. Tailwind scans those files to find used classes — if the content paths do not match your actual file locations, Tailwind finds nothing and generates near-empty CSS. Update the content array with the correct glob patterns for your project structure.
Does Tailwind v4 work in Replit?
Yes. Install with npm install -D tailwindcss@next @tailwindcss/postcss@next. Tailwind v4 uses CSS-first configuration — add @import 'tailwindcss' to your CSS file and configure theme values with @theme { --color-brand: #3b82f6; } directly in CSS. There is no tailwind.config.js in v4. The PostCSS processing setup is the same.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation