Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

How to Add Tailwind CSS to Astro

Add Tailwind CSS to an Astro site with one command, then style your first element. Tested on Astro 7.4 and Tailwind 4.

Tested on Astro 7.4

Cover image for How to Add Tailwind CSS to Astro
In this guide
  1. Step 1: Run the setup command
  2. Step 2: Load the stylesheet
  3. Step 3: Use a class
  4. Where to go from here
  5. Frequently asked questions

Tailwind is a popular way to style a site. Instead of writing CSS rules, you add small classes like text-lg or mt-4 straight to your HTML. Astro has a command that sets it up for you.

Step 1: Run the setup command

In your project folder, run:

npx astro add tailwind

Astro shows you each change it’s about to make and asks you to confirm. Say yes to all of them.

The command does three things:

  1. Installs tailwindcss and the @tailwindcss/vite plugin
  2. Adds the plugin to astro.config.mjs
  3. Creates src/styles/global.css containing a single line, @import "tailwindcss";

Step 2: Load the stylesheet

Tailwind only works on pages that load that CSS file. The easiest way is to import it in your layout, so every page gets it. Open src/layouts/Layout.astro and add the import at the top:

---
import '../styles/global.css';
---

If your project doesn’t have a layout yet, lesson 4 of our course shows how to share a layout across pages.

Step 3: Use a class

Open a page and add some Tailwind classes:

<h1 class="text-3xl font-bold text-blue-700">Welcome to my website</h1>
<p class="mt-4 text-lg">I built this with Astro.</p>

Start your dev server with npm run dev. The heading should be large, bold and blue.

Where to go from here

The Tailwind documentation lists every class. The ones beginners use most are spacing (p-4, mt-2), text (text-xl, font-bold), colour (text-blue-700, bg-gray-100) and layout (flex, grid, gap-4).

You don’t have to use Tailwind. Astro’s built-in scoped styles are enough for many sites, and we use plain CSS on this one. Pick whichever you find easier to read.

Frequently asked questions

Do I need a tailwind.config file?

Not with Tailwind 4. Settings go in your CSS file instead, using the @theme rule. The command in this guide sets up everything you need to start.

Can I use Tailwind and my own CSS together?

Yes. Astro components can have their own style tags, and Tailwind classes work alongside them.

Stuck on a step?

Check the common errors guide, look up a word in the glossary, or ask the friendly people in the official Astro and EmDash Discords. How to ask so people can help.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astronursery.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add a Contact Form to an Astro Site (No Server Needed)

    A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

    Tutorials, 7 minute read, November 8, 2026

Try "blog", "deploy" or "EmDash".