Performance: Arbitrary variants for custom selectors
This affects the CSS selector complexity and browser style calculation time, impacting page rendering speed.
class="bg-red-500 text-lg"class="[&:nth-child(3)]:bg-red-500 [&>div]:text-lg"| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Complex arbitrary variants | No extra DOM nodes | 0 reflows | Higher paint cost due to slower style calculation | [!] Caution |
| Simple utility classes | No extra DOM nodes | 0 reflows | Lower paint cost with fast style calculation | [OK] Good |
<button class="[&:focus-visible]:ring-2 [&:focus-visible]:ring-blue-600">Click me</button>
<div class="[&hover]:bg-red-500">Alert</div>
span inside a div only when the div is hovered, using Tailwind arbitrary variants. Which class should you add to the div?span child only when the div is hovered, so the hover is on the parent.Pass the test and this pattern moves unknown