Sometimes child elements should react to parent or sibling state. Tailwind provides group / group-hover: and peer / peer-checked: variants instead of extra JavaScript.
Group pattern
Mark the parent with group, then style children with group-hover:text-indigo-600 when the parent is hovered—useful for cards where the whole tile is clickable.
Peer pattern
Mark an input with peer; a sibling label uses peer-checked:bg-indigo-600 when the input is checked—common for custom toggles and segmented controls.
Important interview questions and answers
- Q: group vs peer?
A:groupstyles descendants based on ancestor state;peerstyles siblings based on a preceding sibling’s state. - Q: When is this too clever?
A: When markup becomes hard to read—extract a component or use data attributes in JS for complex widgets.
Self-check
- Add
groupto a card and change a child icon color on hover. - Wire a checkbox
peerto toggle a sibling panel’s visibility.
Interview prep
- group vs peer?
groupstyles descendants from ancestor state;peerstyles following siblings from a marked sibling’s state.