State Variants: Hover, Focus, Active, Disabled & Group-Hover
State Variants: Hover, Focus, Active, Disabled & Group-Hover
Dynamic web applications require rich visual feedback when users interact with elements. Tailwind CSS handles pseudo-classes—such as :hover, :focus, :active, :disabled, and :focus-visible—using prefix modifiers. Furthermore, features like group-hover and peer-focus enable complex parent-child and sibling interaction patterns.
1. Core State Modifiers
hover:: Triggered when mouse cursor hovers over the element.focus:/focus-visible:: Triggered when element receives keyboard or click focus.active:: Triggered when mouse is clicked down on the element.disabled:: Triggered when button/input hasdisabledattribute.
2. Parent-Triggered Interactions with group-hover
Often, you want hovering over an entire card to animate an internal icon or change title colors. Mark the parent with group and the child with group-hover::
3. Sibling-Triggered Interactions with peer
To style an element based on the state of a sibling element (e.g., floating form labels), mark the input with peer and sibling with peer-focus::
Multiple Choice Questions
peer modifier allow developers to accomplish?active:scale-95 on a button?Class-Based Dark Mode Setup with System Preference Support
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.