277 words
1 minute
astroにTailwindをインストールするには

astroがインストールされている場所(いつもnpm run devする階層)でnpx astro add tailwindと実行。 デフォルト選択肢通りでインストールをして、astroを再起動します。

インストールログは以下のとおりです。

Terminal window
% npx astro add tailwind
✔ Resolving packages...
Astro will run the following command:
If you skip this step, you can always run it yourself later
╭──────────────────────────────────────────────────────╮
│ npm i @tailwindcss/vite@^4.1.18 tailwindcss@^4.1.18 │
╰──────────────────────────────────────────────────────╯
To run this command without prompts, pass the --yes flag
✔ Continue? … yes
✔ Installing dependencies...
Astro will scaffold ./src/styles/global.css.
✔ Continue? … yes
Astro will make the following changes to your config file:
╭ astro.config.mjs ─────────────────────────────╮
│ // @ts-check │
│ import { defineConfig } from 'astro/config'; │
│ │
│ import tailwindcss from '@tailwindcss/vite'; │
│ │
│ // https://astro.build/config │
│ export default defineConfig({ │
│ vite: { │
│ plugins: [tailwindcss()] │
│ } │
│ }); │
╰───────────────────────────────────────────────╯
✔ Continue? … yes
success Added the following integration to your project:
- tailwind
action required You must import your Tailwind stylesheet, e.g. in a shared layout:
╭ src/layouts/Layout.astro ──────╮
│ --- │
│ import '../styles/global.css' │
│ --- │
╰────────────────────────────────╯

インストール後、test/blog/src/layouts/Layout.astroに以下追記。

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

blog/src/pages/index.astroなどに以下のように記入して、適用されたら成功! ちゃんと太文字で下線が引いてある。

<h1 class="text-3xl font-bold underline">こんにちは</h1>

こんにちは

astroにTailwindをインストールするには
https://fuwari.vercel.app/posts/tailwind-astro/
Author
Lorem Ipsum
Published at
2026-01-19
License
CC BY-NC-SA 4.0