install tailwind css in astro with typescript

In this section we will install & setup Astro + Typescript with Tailwind CSS 3. For this section we will use create-tw it will help to CLI to scaffold tailwindcss-ready projects. Astro is an all-in-one web framework for building fast, content-focused websites.

Features Astro

1.Component Islands: A new web architecture for building faster websites.

2.Server-first API design: Move expensive hydration off of your users’ devices.

3. Zero JS, by default: No JavaScript runtime overhead to slow you down.

4.Edge-ready: Deploy anywhere, even a global edge runtime like Deno or Cloudflare.

5.Customizable: Tailwind, MDX, and 100+ other integrations to choose from.

6.UI-agnostic: Supports React, Preact, Svelte, Vue, Solid, Lit and more.

Create Tailwind CSS Project with Astro

Create tailwind-app with astro using npx:

npx create[email protected]
# OR
npx create[email protected] <project-name> --template <id>

Create tailwind-app with astro using yarn:

yarn create tw
# OR
yearn create tw <project-name> --template <id>

Select astro project.

tailwind css in astro with typescript project

Select typescript with astro.

? Project name astro-tailwind
? App type Astro (create-astro)
tid astro
? What language will your project be written in? (Use arrow keys)
❯ TypeScript 

Select code style.

? Which dependencies would you like to include? (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
❯◯ prettier
 ◯ clsx

Select tailwind plugin.

? Which plugins would you like to include? (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
❯◯ @tailwindcss/typography
 ◯ @tailwindcss/forms
 ◯ @tailwindcss/aspect-ratio

Select npm dependencies, git initialize.

✔ Would you like to install npm dependencies? (recommended) … yes
✔ Packages installed!
✔ Would you like to initialize a new git repository? (optional) … no

Choose typescript setup method in astro.

? How would you like to setup TypeScript? › - Use arrow-keys. Return to submit.
❯  Strict (recommended) - Enable `strict` typechecking rules
  I prefer not to use TypeScript

Move to project and run server.

cd astro-tailwind
npm run dev


// Component Imports
import Button from '../components/Button.astro';

// Full Astro Component Syntax:

<html lang="en">
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<meta name="generator" content={Astro.generator} />
		<title>Astro + TailwindCSS</title>

		<div class="grid place-items-center h-screen content-center">
			<Button>Tailwind Button in Astro!</Button>
			<a href="/markdown-page" class="p-4 underline">Markdown is also supported...</a>
astro with tailwind css typescript

Quick Install Tailwind CSS with Astro CLI

Install Astro with the Automatic CLI

# npm
npm create [email protected]

# yarn
yarn create astro

# pnpm
pnpm create [email protected]

Install @astrojs/tailwind

# Using NPM
npm run astro add tailwind
# Using Yarn
yarn astro add tailwind
# Using PNPM
pnpm astro add tailwind

For more details visit @astrojs/tailwind