0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 09:21:21 +01:00
svelte/documentation/docs/03-template-syntax/16-class.md
Rich Harris 4f6bb41030
More docs stuff (#13769)
* fix

* link

* more docs stuff

* more

* more

* fix

* more

* more

* fix

* fix

* more

* ffs

* FML
2024-10-22 02:11:35 -04:00

591 B

title: class:

The class: directive is a convenient way to conditionally set classes on elements, as an alternative to using conditional expressions inside class attributes:

<!-- These are equivalent -->
<div class={isCool ? 'cool' : ''}>...</div>
<div class:cool={isCool}>...</div>

As with other directives, we can use a shorthand when the name of the class coincides with the value:

<div class:cool>...</div>

Multiple class: directives can be added to a single element:

<div class:cool class:lame={!cool} class:potato>...</div>