---
title: The class directive
---
Like any other attribute, you can specify classes with a JavaScript attribute, seen here:
```svelte
```
This is such a common pattern in UI development that Svelte includes a special directive to simplify it:
```svelte
```
The `selected` class is added to the element whenever the value of the expression is truthy, and removed when it's falsy.