Performance: Peer modifier (sibling state reaction)
This affects how CSS selectors trigger style recalculations and repaints when sibling elements change state.
<button class="peer focus:outline-none">Click me</button> <div class="peer-focus:bg-blue-500">Box</div>
<button id="btn">Click me</button> <div id="box">Box</div> <script> document.getElementById('btn').addEventListener('click', () => { document.getElementById('box').classList.toggle('bg-blue-500'); }); </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| JavaScript toggling sibling class | 1 event listener, 2 DOM updates | Multiple reflows per toggle | Multiple paints | [X] Bad |
| Tailwind peer modifier CSS | No extra DOM ops | Single reflow on state change | Single paint | [OK] Good |
peer modifier in Tailwind CSS allow you to do?peerpeer modifier is used on an element to mark it as a reference for sibling elements.peer-*peer-* classes to change their style based on the peer element's state.peer. -> Option Bpeer modifier in Tailwind CSS?peer on the inputpeer.peer-checked on sibling labelpeer-checked: prefix to style based on the checkbox state.<span> text be when the checkbox is checked?<input type='checkbox' class='peer' id='toggle' /> <span class='peer-checked:text-green-600'>Status</span>
peer, so siblings can react to its state.peer-checked:text-green-600, so when checkbox is checked, text color changes to green.<input type='checkbox' id='check' class='checked' /> <p class='peer-checked:text-red-500'>Warning</p>
<input type='checkbox' class='peer' /> <button class='???'>Submit</button>
checked or focused. We want the button to change background in both cases.peer-checked:bg-blue-600 for checked state and peer-focus:bg-blue-600 for focus state on the sibling button.Pass the test and this pattern moves unknown