Interface: Tailwind Authoring
Rule
Class-level Tailwind guidance for writing cleaner, more consistent UI code.
Markup Hygiene
- MUSTPut
text-*andleading-*classes on block-level text containers, not inline formatting tags like<span>,<a>,<strong>, or<em>unless the inline element is intentionally acting as a text container. - MUST NOTAdd redundant display classes such as
blockon<div>orinlineon<span>unless a variant changes them. - MUST NOTStack conflicting classes for the same property unless a variant, breakpoint, or state distinguishes them.
- SHOULDKeep semantics first. If a list is really a list, use
<ul>or<ol>. - SHOULDAdd
role="list"to<ul>/<ol>when list styling is intentionally removed. - MUSTApply
antialiasedon the app root. - SHOULDApply
isolateon the main app shell so overlays and layering stay predictable.
Class Preferences
- MUSTPrefer
gap-*on the parent overmt-*/mb-*between flex or grid children. - MUSTPrefer
size-*over pairedh-*andw-*when both dimensions match. - MUSTPrefer shorthands like
p-6over split axis classes when values are identical. - SHOULDSplit axes only when one axis genuinely differs or is overridden by a variant.
- MUSTPrefer named scale values over arbitrary values whenever the scale can express the intent.
- MUSTPrefer
z-50style classes overz-[50]; use arbitrary z values only when no scale value works. - MUSTPrefer slash opacity modifiers like
bg-neutral-950/5over bracket opacity syntax. - MUSTUse
remfor arbitrary font sizes, not pixel literals. - MUSTReference design tokens for arbitrary radii, spacing, and colors rather than raw pixel literals.
- SHOULDPrefer
not-*variants over a base class immediately overridden elsewhere. - SHOULDPrefer
data-closed:*style variants over bracket syntax when Tailwind exposes a named variant. - MUSTUse
min-h-dvh,min-h-svh, ormin-h-lvhfor full-height layouts; avoidmin-h-screen. - MUSTUse
bg-linear-*utilities, not legacybg-gradient-*. - MUSTUse
shrink-*/grow-*, notflex-shrink-*/flex-grow-*. - SHOULDKeep grid ratios whole-number and readable when using arbitrary fractional tracks.
- MUST NOTUse named line-height shorthands like
leading-tightfor product UI. Use scale-backed values such asleading-6or combined text/leading shorthands. - MUSTAdd
tabular-numsanywhere numbers change over time or compare against neighboring numbers.
CSS Variable Patterns
- MUSTUse the
--spacing()helper when available instead ofcalc(var(--spacing) * n). - MUSTPrefer CSS variables for arbitrary colors; do not call
theme()inside authored UI code. - SHOULDExpress static CSS variables with arbitrary property syntax rather than inline styles.
- MUSTFor dynamic values, set a CSS variable inline and reference it from the class (
class="w-(--progress)" style="--progress: 72%").
Custom Utilities
- MUSTPrefer
@utilityto ad hoc class selectors in authored Tailwind CSS. - SHOULDUse parameterized
@utilitydefinitions with--value()/--modifier()when the pattern repeats. - SHOULDUse
@variantinside@utilitywhen wiring into existing variants. - MUSTUse
@custom-variantonly for genuinely new semantics. - MUST NOTNest
@utilityinside@mediaor@supports.
Import Order
- MUSTPut remote
@importURLs at the top of the stylesheet, before@import "tailwindcss".
Review Questions
- Are repeated child spacing rules expressed as parent
gap-*? - Are arbitrary values justified, or should they be promoted to tokens or scale values?
- Would a second engineer read this class string and immediately understand the intended hierarchy?