State variants
Put a state in front of a utility and it only applies in that state: hover:shadow-md, dark:hidden, print:hidden. Like the screen-size prefixes (md:flex), but for hover, focus, dark mode, reduced motion and printing.
Hover and focus
hover: only on devices that can hover (no sticky hover after a tap on a phone). focus-visible: when reached with the keyboard.
<a class="box p-4 no-underline transition hover:shadow-md hover:-translate-x-0.5 hover:-translate-y-0.5 hover:bg-yellow-soft" href="#">Lift and color on hover</a>
<a class="box p-4 no-underline transition hover:rotate-2 hover:scale-105" href="#">Tilt</a>
<a class="btn transition focus-visible:bg-yellow" href="#">Tab to me</a>Group hover
Mark a parent with .group; group-hover: on anything inside reacts when the pointer is over the parent, or when keyboard focus is inside it.
<a class="group box p-5 hstack no-underline max-w-md transition hover:shadow-md" href="#">
<span class="feature-icon bg-violet-soft transition group-hover:rotate-6 group-hover:bg-violet"><i class="mi mi-sparkles" aria-hidden="true"></i></span>
<span class="grow"><b>New components</b><br><span class="text-sm text-muted">See what came out this week</span></span>
<i class="mi mi-arrow-right rtl-flip opacity-0 transition group-hover:opacity-100 group-hover:translate-x-1" aria-hidden="true"></i>
</a>Dark and light
Swap a picture or logo by mode: show one with dark:hidden and the other with hidden dark:block. Colors work too: dark:bg-ink. They follow the system setting and the page's own data-momo-mode.
<span class="badge badge-yellow dark:hidden">You're in light mode</span>
<span class="badge badge-violet hidden dark:inline-block">You're in dark mode</span>
<div class="box p-3 bg-yellow-soft dark:bg-violet">Yellow in light, violet in dark</div>Press the moon / sun button at the top of this page to see them change.
Motion and print
motion-safe:animate-pulseonly animates for people who haven't asked for less motion;motion-reduce:hiddenhides something (a moving background, say) for those who have.print:hiddenleaves the navbar, buttons and banners off paper;hidden print:blockshows something only when printed (a URL, a "printed on" line).
Which utilities each state has
| Prefix | Works with |
|---|---|
hover: | Colors (bg-*, text-*, border-*), shadows, opacity-0/50/75/100, small transforms (rotate-1…6, scale-95…110, translate-x/y-0.5…2), underline, grayscale / grayscale-0 / blur-sm / blur-none |
group-hover: | The same, plus show / hide (hidden, block, flex, invisible…) |
focus-visible: | Colors, shadows, underline |
dark: | Colors, show / hide |
light:, print: | Show / hide |
motion-safe:, motion-reduce: | transition*, animate-*, show / hide |
Each state gets only what is useful with it, so the file stays small. For anything else, write a line of CSS.