Capítulo 10 de 29
Tailwind's whole approach is composing many small single-purpose utility classes directly in markup instead of writing custom CSS with named selectors — this trades "thinking in CSS files" for "thinking in HTML classes," and is deliberately more constrained than inline styles because utilities pull from a shared design system and support states/media queries that inline styles can't.
hover:, focus:) and media/container queries (md:, @md:).hover:bg-sky-700 generates &:hover { background-color: ... } — the class does nothing unless hovered. This is the opposite of a traditional .btn class that bundles base + hover styles together; in Tailwind you always see both states as separate classes on the element itself. Variants stack (disabled:hover:bg-sky-500).filter utilities: blur-sm, grayscale) each set only their own CSS variable, and the property's value references all of them (falling back to nothing when unset) — so blur-sm grayscale combines cleanly instead of one overwriting the other. Same mechanism powers gradients, shadow colors, and transforms.bg-[#316ff6] for one-off values, grid-cols-[24rem_2.5rem_minmax(0,1fr)] for complex values, calc() combined with theme functions (max-h-[calc(100dvh-(--spacing(6)))]), and fully arbitrary CSS variable properties ([--gutter-width:1rem]).dark:lg:data-current:hover:bg-indigo-600); group/group-hover: styles a descendant based on an ancestor's state (mark the ancestor group, target descendants with group-hover:); arbitrary variants ([&>[data-active]+span]:text-blue-600) cover selectors with no built-in variant, especially useful when you don't control the surrounding HTML.style={{ '--bg-color': buttonColor }} and then consuming it with a utility (bg-(--bg-color)), keeping the state/variant behavior utilities give you while sourcing the raw value dynamically.@layer components class (e.g. .btn-primary built from theme variables) only when a template partial feels like overkill for something trivial, and only for single-element cases — prefer partials for anything more complex.class attribute — so never apply two utilities that target the same property to the same element; branch the class value instead (e.g. gridLayout ? "grid" : "flex"), or expose a prop from a component rather than letting consumers add conflicting classes from outside.! important modifier: append ! to a class (bg-red-500!) to force !important on just that utility's declarations, for cases with no other way to win a specificity fight.important import flag: @import "tailwindcss" important; marks every generated utility !important — useful when integrating Tailwind into a project with existing high-specificity legacy CSS.// dynamic value via CSS variable + utility, keeps hover/variant support
<button
style={{ "--bg-color": buttonColor, "--bg-color-hover": buttonColorHover }}
className="bg-(--bg-color) hover:bg-(--bg-color-hover) ..."
>
{children}
</button>
<a href="#" class="group rounded-lg p-8">
<span class="group-hover:underline">Read more…</span>
</a>
group/group-hover: parent-state pattern.@layer components class — don't jump straight to a custom CSS class.! (per-class) and the important import flag (global) exist for specificity fights, not as a default habit — both are last resorts.blur-sm grayscale combines instead of one canceling the other.hover:, group-hover:, arbitrary variants) are covered in full there.@layer components and arbitrary-value/property/variant syntax are documented in depth there.