|center Filter

centers a value within text of n characters

Formatting As Markdown

Argument
n (required) – The width of the field in number of characters, in which to center the value.

Documentation

Alignment filters add whitespace on one or both sides of the value.

Variable

company = 'Webucator'

Template

{{ "company|center:20" }}

Result

"     Webucator      "

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

" Webucator "

Commentary

As whitespace is condensed by default in HTML pages, alignment filters wouldn’t affect the output unless the text is within a pre element or CSS is used to prevent whitespace from being condensed. However, Django can be used to create non-HTML documents as well. In such documents, formatting with whitespace might make more sense.

More Formatting Filters

All Formatting Filters


Did we get something wrong? Is there a use case for the center filter that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on August 2, 2026