Svelte · Junior · Question 26 of 76

How can you pass several classes conditionally in Svelte 5?

<div class={["card", { active: isActive, disabled }]}></div>

Explanation

Objects and arrays in class are supported since Svelte 5.16. The class: directive still works but is no longer the recommended approach.

Further reading

Problem with a question

Svelte · Junior · question 26

Test yourself

Take the Svelte · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz