For a site that is mostly Markdown I use plain CSS: one global stylesheet with CSS variables, plus small scoped <style> blocks in components. This month I started a small dashboard for HygroMonitor, a status page that shows the latest readings and the state of each sensor node. For that one I used Tailwind CSS v4.
Adding Tailwind v4 to Astro
Tailwind v4.0 was released in January 2025. A few days later Astro 5.2 added support for it. The old @astrojs/tailwind integration is deprecated. Tailwind v4 has its own Vite plugin, @tailwindcss/vite, and Astro uses that directly.
The easy way:
npx astro add tailwind
This installs tailwindcss and @tailwindcss/vite, adds the plugin to the config, and creates a CSS file that imports Tailwind. The result in astro.config.mjs:
import { defineConfig } from 'astro/config';
import tailwindcss from '@tailwindcss/vite';
export default defineConfig({
vite: {
plugins: [tailwindcss()],
},
});
Then import the CSS file once, in the base layout:
---
// src/layouts/Base.astro
import '../styles/global.css';
---
There is no tailwind.config.js and no PostCSS config. If you have an older project with @astrojs/tailwind, remove it from integrations and from package.json first. I had both installed for a moment and got confusing results.
CSS-first config
The whole Tailwind setup now lives in CSS:
/* src/styles/global.css */
@import "tailwindcss";
@theme {
--color-ok: oklch(0.72 0.17 150);
--color-warn: oklch(0.80 0.16 85);
--color-fail: oklch(0.63 0.22 25);
--font-sans: "Inter", system-ui, sans-serif;
}
Each variable in @theme creates utilities. --color-ok gives bg-ok, text-ok, border-ok and so on. The variables are also output as normal CSS variables on :root, so you can use var(--color-ok) in plain CSS, for example in a chart library config. I like this part a lot. In v3 the tokens lived in JavaScript and you had to copy them if you needed them in CSS.
To remove the default palette and keep only your own colors, reset the namespace first:
@theme {
--color-*: initial;
--color-ok: oklch(0.72 0.17 150);
}
Plugins are also added in CSS, for example @plugin "@tailwindcss/typography";.
What changed from v3
I have one older project on v3, so I noted the differences that affected me:
@tailwind base; @tailwind components; @tailwind utilities;is replaced by one@import "tailwindcss";.- No
contentarray. Tailwind finds your source files itself and skips files in.gitignore. If classes come from a place it does not scan (a package innode_modules, for example), add it with@source "../path";. - Some utilities were renamed, one step down the scale:
shadow-smis nowshadow-xs,shadowisshadow-sm. The same forroundedandblur.outline-noneis nowoutline-hidden. ringis now 1px by default (it was 3px). Usering-3for the old look.- The default border color is now
currentColor, not a light gray. Borders without a color class suddenly looked dark. - Dark mode with a class is configured with
@custom-variant dark (&:where(.dark, .dark *));. - A v3 JavaScript config can still be loaded with
@config "./tailwind.config.js";while you migrate. - It targets modern browsers only: Safari 16.4+, Chrome 111+, Firefox 128+. For a dashboard on my own devices that is fine. For a public site, check your audience first.
There is an upgrade tool, npx @tailwindcss/upgrade. It did most of the renames in my v3 project. I still went through the pages by eye afterwards, because of the border color change.
One pitfall in Astro: if you use @apply inside a component’s <style> block, that block is processed alone and does not know your theme. Add a reference to the main stylesheet at the top of the block:
<style>
@reference "../styles/global.css";
.badge { @apply rounded-sm px-2 text-xs; }
</style>
Without it you get an error about an unknown utility class. I try not to use @apply much anyway.
Why the dashboard uses Tailwind
The dashboard is mostly layout and small UI pieces: a grid of cards, badges for “ok”, “stale” and “offline”, a table, some spacing. Almost all markup is in components that I write once and reuse. Tailwind fits this well:
- I do not have to name things. A card is a component, so the classes live in one place.
- Responsive layout is quick:
grid gap-4 sm:grid-cols-2 lg:grid-cols-3and I am done. - The output CSS contains only what I use, so it stays small without any effort.
- Changing a status color in
@themechanges it everywhere.
For a page that is mostly UI and built from components, I am faster with it.
Why Markdown-heavy sites stay on plain CSS
A content site is the opposite case. Most pages are Markdown. The HTML comes from the Markdown renderer, so I cannot put utility classes on a <p> or a <pre>. I would need the typography plugin and its prose classes, and then customize that plugin to look like what I already have. That is more config to get to the same result.
The few templates such a site has are small, and the CSS for them is short and readable. A post list item with Tailwind has a long class list that I find harder to read than a few lines of CSS with a clear class name. In a content-heavy page those long lists are mostly noise.
And the design tokens can simply be CSS variables:
:root {
--text: #1f2328;
--muted: #59636e;
--accent: #0b6bcb;
--measure: 70ch;
}
Tailwind v4 would turn these into @theme variables and give me utilities for them. But a content site would not use most of those utilities. Adding a build dependency to a site that should stay simple for many years is not worth it for me. Plain CSS will still work the same way in ten years. I am less sure about any CSS framework.
My rule for now
If the project is mostly components and UI, I use Tailwind v4. If it is mostly content from Markdown, I use plain CSS with variables, maybe with a small scoped style here and there. A mix is also fine: the dashboard has one Markdown “about” page, and that page uses the typography plugin.