Search code examples
sveltesvelte-3

How to apply multi classes to an element/ combine conditional static classes


I want to apply multiple css classes to one element. How do I do it? One conditional and one static.

  <p
    class={current === 'overview' ? 'selected' : '' // here I want to add another class named foo}
    on:click={() => (current = 'overview')}
  >

Solution

  • To make life easier you can use the class: directive

    <p class="foo" class:selected={current === 'overview'}>