HTML & CSS · Middle · Question 42 of 75

Why can't you build a Tailwind class name like ` bg-${color}-500 `?

Explanation

Tailwind doesn't run your code; it statically scans files for class-like tokens. The string bg-${color}-500 doesn't contain a complete name, so bg-red-500 isn't generated. The right way is mapping to full names: { red: "bg-red-500", blue: "bg-blue-500" }[color].

Further reading

Problem with a question

HTML & CSS · Middle · question 42

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