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 in the official Astro Discord, where the support channels are friendly to beginners.

Keep reading

  1. How to Deploy an Astro Site to Cloudflare Workers

    Put your Astro site online with Cloudflare Workers in four steps. This is how AstroBeginner itself is hosted, so every step has been run for real.

    Tutorials, 7 minute read, November 6, 2026

  2. How to Add Images to an Astro Site

    Add an image to your Astro site, and let Astro shrink and convert it automatically. One test image went from 62 kB to 5 kB.

    Tutorials, 6 minute read, November 6, 2026

  3. How to Add a Sitemap to Astro

    Create a sitemap for your Astro site in three steps, so search engines can find every page. Includes the robots.txt line.

    Tutorials, 4 minute read, November 6, 2026

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