Why does Tailwind group styles into "layers"?
In CSS, the order of the rules in your stylesheet decides which declaration wins when two selectors have the same specificity:
.btn {
background: blue;
/* ... */
}
.bg-black {
background: black;
}
Here, both buttons will be black since .bg-black
comes after .btn
in the CSS:
<button class="btn bg-black">...</button>
<button class="btn bg-black">...</button>
To manage this, Tailwind organizes the styles it generates into three different "layers" — a concept popularized by ITCSS.
- The
base
layer is for things like reset rules or default styles applied to plain HTML elements. - The
components
layer is for class-based styles that you want to be able to override with utilities. - The
utilities
layer is for small, single-purpose classes that should always take precedence over any other styles.
Being explicit about this makes it easier to understand how your styles will interact with each other, and using the @layer
directive lets you control the final declaration order while still organizing your actual code in whatever way you like.
read more https://tailwindcss.com/docs/adding-custom-styles#adding-base-styles