# attr()

Generates a list of HTML attributes

****

- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/helpers.php#L44>

****

```php
attr(array|null $attr = null, string|null $before = null, string|null $after = null): string|null
```

## Parameters

| Name | Type | Default | Description |
| ---- | ---- | ---- | ---- |
| `$attr` | `array` or `null` | `null` | A list of attributes as key/value array |
| `$before` | `string` or `null` | `null` | An optional string that will be prepended if the result is not empty |
| `$after` | `string` or `null` | `null` | An optional string that will be appended if the result is not empty |

## Return types

`string` or `null`

## Examples

```php
<?php if ($image = $page->image()): ?>
    <figure<?= attr(['class' => 'gallery', 'data-ratio' => '16/9'], ' ', ' ') ?>>
        <img src="<?= $image->url() ?>" alt="<?= $image->alt() ?>">
    </figure>
<?php endif ?>
```