# $field->escape()

Escapes the field value to be safely used in HTML templates without the risk of XSS attacks

****

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

****

```php
$field->escape(string $context = 'html'): Kirby\Content\Field
```

## Parameters

| Name | Type | Default | Description |
| ---- | ---- | ---- | ---- |
| `$context` | `string` | `'html'` | Location of output (`html`, `attr`, `js`, `css`, `url` or `xml`) |

## Return type

`Kirby\Content\Field`

This method modifies the existing `$field` object it is applied to and returns it again.

## Aliases

You can use the following aliases for this field method in your template:

- `$field->esc(…)`

## Examples

```php
<p><?= $page->text()->escape() ?></p>
```

```php
<img alt="<?= $image->alt()->escape('attr') ?>" src="<?= $image->url() ?>" />
```

```php
<section style="--columns: <?= $section->columns()->escape('css')">
...
</section>
```

```php
<script>
let yourVariable = "<?= $page->jsVariable()->escape('js') ?>";

// ...
</script>
```

```php
<iframe src="https://map.example.com/?lat=<?= $map->lat()->escape('url') ?>&lon=<?= $map->lon()->escape('url') ?>"></iframe>
```