Add the prefix to only apply a utility on hover.

State Variants - 图2

By default, hover variants are only generated for background color, border color, font weight, shadow, text color, and text style utilities.

You can customize this in the of your configuration file.

Focus

Add the focus: prefix to only apply a utility on focus.

State Variants - 图4

By default, focus variants are only generated for background color, border color, font weight, outline, shadow, text color, and text style utilities.

Add the active: prefix to only apply a utility when an element is active.

State Variants - 图6

By default, active variants are not generated for any utilities.

You can customize this in the of your configuration file.

Group Hover

If you need to style a child element when hovering over a specific parent element, add the .group class to the parent element and add the group-hover: prefix to the utility on the child element.

State Variants - 图8

By default, group hover variants are not generated for any utilities.

Add the focus-within: prefix to only apply a utility when a child element has focus.

State Variants - 图10

By default, focus-within variants are not generated for any utilities.

You can customize this in the of your configuration file.

Responsive Prefixes

State variants are also responsive, meaning you can change an element’s hover style for example at different breakpoints.

To apply a state variant responsively, add the responsive prefix first, before the state prefix.

You can generate state variants for your own custom utilities using the @variants directive:

  1. // Input:
  2. .banana {
  3. color: yellow;
  4. }
  5. }
  6. // Output:
  7. .banana {
  8. }
  9. .focus\:banana:focus {
  10. color: yellow;
  11. }
  12. .hover\:banana:hover {
  13. color: yellow;
  14. }