---
title: '|linenumbers'
description: prepends each line of text with a line number.
date: '2026-08-02'
categories:
  - Filter
  - String
canonical: https://www.djangotemplatetagsandfilters.com/filters/linenumbers/
doc_link: https://docs.djangoproject.com/en/6.0/ref/templates/builtins/#linenumbers
---

# |linenumbers

prepends each line of text with a line number.

## Documentation

Prepends each line of text with a line number.

### Variable

```django
shopping_list = '''Carrots
Honey
Milk
Butter'''
```

### Template

```django
{{ shopping_list|linenumbers }}
```

### Result

```django
1. Carrots
2. Honey
3. Milk
4. Butter
```

In a browser, whitespace is condensed, so the output would be:

1. Carrots
2. Honey
3. Milk
4. Butter

## Commentary

Useful for plain text, but not typically for HTML.
