HTML & CSS · Middle · Question 74 of 75

How do you style an element based on a data-state attribute in Tailwind?

<div data-state="open" class="data-[state=open]:bg-zinc-100">...</div>

Explanation

Headless UI libraries (Radix, Headless UI) expose state via data-* and ARIA attributes, so data-[state=open]: and aria-expanded: variants style them without extra classes.

Further reading

Problem with a question

HTML & CSS · Middle · question 74

Test yourself

Take the HTML & CSS · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz