---
title: truncate
description: "Shorten text to a character limit."
---

# truncate

Shorten text to a character limit.

## Syntax

```knap
{{ value | truncate:100 }}
{{ value | truncate:(100, "...") }}
```

## Usage

- The required first parameter is a non-negative character limit.
- The suffix defaults to `…`. Pass a second parameter to replace it, or `""` to omit it.
- The suffix counts toward the character limit and is clipped when it is longer than the limit.
- Unicode grapheme clusters such as emoji count as one character.
- For arrays and objects, including serialized collections from another filter, string values are formatted recursively while keys and non-string values are preserved.

## Examples

### Default suffix

```json title="Data"
{
  "text": "A concise introduction to Knap"
}
```

```knap title="Template"
{{ text | truncate:10 }}
```

```md title="Output"
A concise…
```

### Custom suffix

```json title="Data"
{
  "text": "A concise introduction"
}
```

```knap title="Template"
{{ text | truncate:(12, "...") }}
```

```md title="Output"
A concise...
```

### No suffix

```json title="Data"
{
  "text": "A concise introduction"
}
```

```knap title="Template"
{{ text | truncate:(9, "") }}
```

```md title="Output"
A concise
```

## Related filters

- [truncatewords](/filters/truncatewords)
