<div class="group">
<span>Hover me</span>
</div>Option C uses group-hover as the variant and applies the arbitrary selector [&>span] to target the direct child span. This means when the parent div with class group is hovered, the span inside gets the red text color.
Other options either misuse the order or the selector syntax.
element only when the preceding
sibling is focused?
<h2 tabindex="0">Title</h2>
<p>Paragraph</p>.
Option B correctly uses the arbitrary variant [&:focus+p] to target the
that is immediately after the focused element (the
).
Option B incorrectly places focus: before the arbitrary variant, which does not work as intended. Option B targets the wrong element and option B uses the general sibling combinator (~) which is not the immediate sibling.
[&:not(:last-child)]:mb-4 on a list of The arbitrary variant [&:not(:last-child)] applies styles to all elements except the last child. So mb-4 (margin-bottom 1rem) is added to every
<button>Click me</button>
Option A uses the built-in focus-visible variant correctly to apply an outline only when the button is focused via keyboard (not mouse). This improves accessibility by showing focus only when needed.
Option A tries to use arbitrary variants unnecessarily. Option A and D use focus which triggers on mouse focus too, not just keyboard.
- only when the
- is hovered?
<ul class="hover:[&>li]:text-green-500"> <li>Item 1</li> <li>Item 2</li> </ul>
Option A uses the arbitrary variant [&:hover>li] which means when the element itself is hovered, target its direct li children. This correctly applies the green text color to all li inside the hovered ul.
Option A tries to combine hover variant with arbitrary variant incorrectly. Option A applies hover on li instead of ul. Option A nests hover twice incorrectly.
Practice
Solution
Step 1: Understand Tailwind's arbitrary variants
Arbitrary variants let you write custom CSS selectors inside Tailwind by wrapping them in square brackets.Step 2: Compare options
Only Use custom CSS selectors inside Tailwind classes correctly describes this feature; others describe unrelated Tailwind features.Final Answer:
Use custom CSS selectors inside Tailwind classes -> Option AQuick Check:
Arbitrary variants = custom selectors [OK]
- Thinking arbitrary variants change colors
- Confusing with JavaScript or responsive features
- Assuming it disables Tailwind features
Solution
Step 1: Understand arbitrary variant syntax
Arbitrary variants use square brackets with a selector inside, e.g., [&:hover].Step 2: Identify correct usage for hover
[&:hover]:text-blue-500 uses the correct syntax: [selector]:utility, here [&:hover]:text-blue-500.Final Answer:
[&:hover]:text-blue-500 -> Option BQuick Check:
Arbitrary variant syntax = [&:hover]:utility [OK]
- Adding 'hover:' before arbitrary variant
- Using brackets without &
- Misplacing brackets around 'hover'
<button class="[&:focus-visible]:ring-2 [&:focus-visible]:ring-blue-600">Click me</button>
Solution
Step 1: Analyze the arbitrary variant selectors
The class uses [&:focus-visible] which applies styles only when the button is focused and visible.Step 2: Understand the applied styles
ring-2 and ring-blue-600 add a blue outline ring of thickness 2 on focus-visible state.Final Answer:
The button gets a blue ring when it is focused and visible -> Option CQuick Check:
Arbitrary variant with :focus-visible = ring on focus [OK]
- Thinking ring is always visible
- Confusing focus-visible with hover
- Ignoring the arbitrary variant selector
<div class="[&hover]:bg-red-500">Alert</div>
Solution
Step 1: Check the arbitrary variant syntax
The pseudo-class hover must be preceded by a colon and ampersand inside brackets: [&:hover].Step 2: Identify the mistake
The class uses [&hover] missing the colon, so it is invalid syntax.Final Answer:
Incorrect pseudo-class syntax, should be [&:hover] -> Option AQuick Check:
Pseudo-class needs colon after & [OK]
- Omitting colon before pseudo-class
- Using brackets incorrectly
- Assuming bg-red-500 is invalid
span inside a div only when the div is hovered, using Tailwind arbitrary variants. Which class should you add to the div?Solution
Step 1: Understand the selector goal
You want to style thespanchild only when thedivis hovered, so the hover is on the parent.Step 2: Choose correct arbitrary variant syntax
The selector [&:hover>span] means when the div is hovered, style its direct child span.Step 3: Check other options
[&>span:hover]:text-green-600 styles span on its own hover, not div's hover. hover:[&>span]:text-green-600 and D have incorrect syntax or order.Final Answer:
[&:hover>span]:text-green-600 -> Option DQuick Check:
Parent hover affecting child = [&:hover>span] [OK]
- Applying hover on child instead of parent
- Misplacing brackets or colons
- Using hover: outside arbitrary variant incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
