Tailwind requires PostCSS or Vite in your toolchain, so the easiest way to use Tailwind is through a framework like Astro.
You don’t have to worry much about the dev-tooling process nowadays. Most frameworks are quite intuitive here. So grab the framework, use a minimal starter template, and you’re ready to go.
I like to use Astro and I recommend it because:
- It is really easy for beginners to pick up.
- It is very friendly when it comes to HTML, CSS, and JavaScript basics.
- It lets you use any frontend framework, so there’s flexibility and less vendor lock-in.
The downside is Astro introduces a few styling issues, but I argue it’s a lot less headache when compared to certain frameworks like React.
Installing Tailwind in Astro
Follow this guide to install Tailwind in Astro. It’s a pretty straightforward process so you will likely not run into problems here.
Importing Tailwind
A quick gotcha here.
The easiest way to import Tailwind into your projects is through importing the library:
/* This is the gotcha */@import 'tailwindcss';If you import this, you’ll likely be taken aback quickly — because Tailwind has aggressive preflight styles (basically, their CSS reset and base styles) that completely change what you would normally expect form a standard CSS Reset file like yours’ truly.
So I omit Tailwind’s preflight styles.
You can do so by importing Tailwind’s base and utilities manually.
/* Start Tailwind CSS without preflight */@layer theme, base, components, utilities;@import 'tailwindcss/theme.css' layer(theme);@import 'tailwindcss/utilities.css' layer(utilities);Now you’re ready to begin using Tailwind.
One more thing before we move on
I tend to include a reset layer before the base layer so I can include my own resets. This is optional. It’s perfectly fine to include resets in theme or base.
@layer reset, theme, base, components, utilities;You can see that Tailwind uses CSS Cascade Layers in the quick example above. This is really handy — you’ll learn more in the Unorthodox Fundamentals chapter.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson