CSS Layer Directives
What you'll learn: How to use @tailwind directives to inject Tailwind's pre-built styles into your CSS file in three distinct layers.
The Three Magic Ingredients
Think of Tailwind CSS like a recipe kit with three separate containers: one for basic resets, one for reusable components, and one for utility classes. The @tailwind directives are how you pour each container into your stylesheet.
The Three Layer Directives
When you set up Tailwind CSS, you'll add these three directives to your main CSS file (often styles.css or input.css):
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind base
This injects Tailwind's base styles — normalize/reset rules and default element styling. It ensures consistent cross-browser rendering and provides sensible defaults for HTML elements.
@tailwind components
This layer holds component classes — pre-styled UI patterns like buttons or cards. By default it's empty, but you can add your own reusable component styles here using Tailwind's @layer components directive (which you'll learn later).
@tailwind utilities
This is where all the utility classes live — the .flex, .text-center, .bg-blue-500 classes that make utility-first CSS powerful. This layer gets injected last so utilities can override everything else.
Why the Order Matters
The order follows the specificity pyramid: base styles apply broadly, components are more specific, and utilities win all conflicts. This cascade ensures your utility classes always work as expected without needing !important.
Key Takeaway: The three @tailwind directives (base, components, utilities) inject Tailwind's styles in layers from least to most specific, creating a predictable cascade for utility-first development.