Skip to content

noSvelteClassDirective (HTML)

Language HTML
biome.json
{
"linter": {
"rules": {
"nursery": {
"noSvelteClassDirective": "error"
}
}
}
}

Disallow Svelte’s class: directive.

The class: directive adds one class to an element when a condition is true. Since Svelte 5.16, the class attribute accepts objects and arrays, which can do the same. Svelte recommends the class attribute, because an object or an array can add several classes with one condition, and can be combined with other class values, such as the classes that a component receives from its parent.

Objects and arrays in the class attribute need Svelte 5.16 or later. This rule doesn’t check which Svelte version your project uses, so turn it off if your project uses an older version.

<div class:active={isActive}></div>
code-block.svelte:1:6 lint/nursery/noSvelteClassDirective ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This class: directive can be replaced with the class attribute.

> 1 │ <div class:active={isActive}></div>
│ ^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Since Svelte 5.16, the class attribute accepts objects and arrays. Unlike the directive, they can add several classes with one condition and can be combined with other class values.

ℹ Move the class into the element's class attribute, using an object such as class={{ active: isActive }}.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<div class:active></div>
code-block.svelte:1:6 lint/nursery/noSvelteClassDirective ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This class: directive can be replaced with the class attribute.

> 1 │ <div class:active></div>
│ ^^^^^^^^^^^^
2 │

ℹ Since Svelte 5.16, the class attribute accepts objects and arrays. Unlike the directive, they can add several classes with one condition and can be combined with other class values.

ℹ Move the class into the element's class attribute, using an object such as class={{ active: isActive }}.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<div class={{ active: isActive }}></div>
<div class={{ active }}></div>
<div class={["button", isActive && "active"]}></div>
<div class={isActive ? "active" : "inactive"}></div>