---
title: '|safe'
description: >-
  indicates that the value is known to be safe and therefore does not need to be escaped.
date: '2026-08-02'
categories:
  - Filter
  - Coding
canonical: https://www.djangotemplatetagsandfilters.com/filters/safe/
doc_link: https://docs.djangoproject.com/en/6.0/ref/templates/builtins/#safe
---

# |safe

indicates that the value is known to be safe and therefore does not need to be escaped.

## Documentation

The `safe` filter indicates that the value is known to be safe and therefore does not need to be escaped. For example, given the following:

```django
blurb = '<p>You are <em>pretty</em> smart!</p>'
```

This would return *unescaped* HTML to the client:

```django
{{ blurb|safe }}
```

### Result

```django
<p>You are <em>pretty</em> smart!</p>
```

The client (e.g., a browser) would then interpret was returned, so your users would see this HTML in the browser:

You are *pretty* smart!

> ### Warning 1: Not for JavaScript
> The `safe` filter is **not** to be used for escaping JavaScript code.
> See Adam Johnson’s [Safely Including Data for JavaScript in a Django Template](https://adamj.eu/tech/2020/02/18/safely-including-data-for-javascript-in-a-django-template/) for details.

> ### Warning 2: Not for User-entered Data
> Never trust user-entered data. Only use this if you are sure the content is safe (i.e., you wrote it).

## Commentary

In most cases, we recommend using this filter instead of the [`autoescape`](/tags/autoescape/) tag, because it is specific to a variable and less likely to result in unintended (and potentially dangerous) output. However, you must be careful with the `safe` filter as well.

Consider the following:

### Variable

```django
blurb_dangerous = '<script>alert("Danger!");</script>'
```

### Template

```django
{{ blurb_dangerous|safe }}
```

### Result

```django
<script>alert("Danger!");</script>
```

See the commentary on the [`autoescape`](/tags/autoescape/) tag for more details.
