Given this HTML and Tailwind CSS, what color will the <span> text become when you hover over the <button>?
<button class="peer hover:bg-blue-500 p-2">Hover me</button> <span class="peer-hover:text-red-600">Change me</span>
<button class="peer hover:bg-blue-500 p-2">Hover me</button> <span class="peer-hover:text-red-600">Change me</span>
Remember, peer-hover applies styles to siblings when the peer is hovered.
The peer class on the button allows the sibling span to react to the button's hover state using peer-hover. So when you hover the button, the span text color changes to red.
Consider this snippet:
<input type="checkbox" class="peer hidden" id="toggle" /> <label for="toggle" class="cursor-pointer">Toggle</label> <div class="peer-checked:block hidden p-4 bg-green-200">Content</div>
What happens to the <div> when the checkbox is checked?
<input type="checkbox" class="peer hidden" id="toggle" /> <label for="toggle" class="cursor-pointer">Toggle</label> <div class="peer-checked:block hidden p-4 bg-green-200">Content</div>
Think about how peer-checked works with hidden inputs.
The peer-checked:block class makes the div display as block only when the checkbox (peer) is checked. Otherwise, it stays hidden.
Given this structure:
<div>
<button class="peer">Click</button>
<section>
<span class="peer-hover:text-blue-600">Text</span>
</section>
</div>Why does the peer-hover class on the span not change its color when hovering the button?
<div> <button class="peer">Click</button> <section> <span class="peer-hover:text-blue-600">Text</span> </section> </div>
Think about the relationship between peer and the element using peer-hover.
The peer-hover modifier only affects elements that are siblings of the element with the peer class. Since the span is inside a section, it is not a sibling of the button, so the style does not apply.
Which approach ensures that keyboard users see the same peer-hover styles when focusing the peer element?
<button class="peer hover:bg-yellow-300">Focus me</button> <div class="peer-hover:text-yellow-600">Highlight me</div>
<button class="peer hover:bg-yellow-300">Focus me</button> <div class="peer-hover:text-yellow-600">Highlight me</div>
Keyboard users trigger focus, not hover.
Keyboard users navigate with focus, so adding peer-focus ensures the sibling changes style when the peer is focused, matching hover behavior for mouse users.
What happens when you use this class?
<button class="peer-hover:bg-red-500">Click</button>
Why?
<button class="peer-hover:bg-red-500">Click</button>Think about what peer-hover targets.
The peer-hover modifier applies styles to siblings when the peer element is hovered. Using it on the element itself does nothing because it is not a sibling of itself.