Skip to content
djlintPublic

About

HTML template formatter and linter for Django, Jinja, Twig, Nunjucks, Handlebars, Mustache, Liquid, Go templates, Angular, Tera, Askama and Mako. Formats markup and template syntax together, and lints for accessibility, correctness and style. CLI, language server (LSP), pre-commit hook and VS Code extension.

Topics

Resources

Stars

961 stars

Watchers

8 watching

Forks

Repository files navigation


djLint Logo

The missing formatter and linter for HTML templates.

Downloads Discord

Template languages

Django • Jinja • Twig • Nunjucks • Handlebars • Mustache • Liquid • Go templates • Angular • Tera • Askama • Mako

🤔 For What?

Generic HTML tools can't parse {% %} and {{ }}, and template engines don't care what the markup around them looks like. So indentation drifts, tags go unclosed and spacing goes wherever, and none of it gets caught in review.

djLint reads HTML and the template syntax inside it, with profiles for Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, Go templates and more. It runs from the command line, as a pre-commit hook and as a language server in your editor.

Take a template only its author could love:

{% block content %}
<SECTION class="posts">


<h2>Latest posts</h2>
{%if posts%}
<ul>
{% for post in posts %}
<li>
<a href="{% url 'post' post.slug %}" class="post-link {%if post.featured%}is-featured{%endif%}" data-analytics-id="post-{{post.id}}" aria-label="Read {{post.title}}">{{post.title|title}}</a>
</li>
{% endfor %}
</ul>
{%else%}
<p>No posts yet.</p>
{%endif%}
</SECTION>
{% endblock %}

One djlint --reformat later:

{% block content %}
    <section class="posts">
        <h2>Latest posts</h2>
        {% if posts %}
            <ul>
                {% for post in posts %}
                    <li>
                        <a href="{% url 'post' post.slug %}"
                           class="post-link {% if post.featured %}is-featured{% endif %}"
                           data-analytics-id="post-{{ post.id }}"
                           aria-label="Read {{ post.title }}">{{ post.title|title }}</a>
                    </li>
                {% endfor %}
            </ul>
        {% else %}
            <p>No posts yet.</p>
        {% endif %}
    </section>
{% endblock %}

One command rebuilt the indentation, fixed the tag case, spread the long tag over lines, normalized the template tags and collapsed stray blank lines.

Rather indent the attributes under the tag and give the closing bracket a line of its own, as Prettier does? Add --single-attribute-per-line:

<a
    href="{% url 'post' post.slug %}"
    class="post-link {% if post.featured %}is-featured{% endif %}"
    data-analytics-id="post-{{ post.id }}"
    aria-label="Read {{ post.title }}"
>{{ post.title|title }}</a>

The linter catches what formatting can't fix: orphan tags, missing alt attributes, hard-coded URLs and dozens of other checks.

You can try it on your own templates in the online playground.

✨ How?

Add it to your project as a development dependency with uv, or install it with pip. In a JavaScript project, npm adds it with a Python of its own:

uv add --dev djlint
# or
pip install djlint
# or
npm i -D djlint

Put uv run or npx in front of the commands below if you used uv or npm, as in uv run djlint . --lint. The installation guide also covers installing it as a standalone tool, and with pipx or Homebrew.

Lint your project:

djlint . --lint

See what formatting would change:

djlint . --check

Format the files in place:

djlint . --reformat

Set a --profile for the rules and formatting of your template language:

djlint . --reformat --profile=django

Or run it with pre-commit, formatting first and then linting:

repos:
  - repo: https://github.com/djlint/djLint
    rev: v1.54.0 # use the latest version instead
    hooks:
      - id: djlint-reformat
      - id: djlint

🧩 Editors

💙 Like it?

Add a badge to your project's readme.md:

[![html style: djLint](https://img.shields.io/badge/html%20style-djLint-blue.svg)](https://djlint.com)

Add a badge to your readme.rst:

.. image:: https://img.shields.io/badge/html%20style-djLint-blue.svg
   :target: https://djlint.com

Looks like this:

html style: djLint

🛠️ Can I help?

Yes!

Would you like to add a rule to the linter? Take a look at the linter docs and the rule definitions.

Local setup takes two commands:

# install uv first: https://docs.astral.sh/uv/getting-started/installation/
uv sync

# run the test suite
uv run pytest

🏃 Other tools of note

  • djade A fast Django template formatter that formats template syntax whilst leaving HTML as-is, and applies fixes for older Django versions.
  • djangofmt A fast, HTML-aware Django/Jinja template formatter written in Rust that formats HTML and template syntax together.
  • DjHTML A pure-Python Django/Jinja template indenter without dependencies.
  • prettier-plugin-jinja-template Prettier plugin for formatting Jinja and Django templates.
  • prettier-plugin-twig Prettier plugin for formatting Twig templates.
  • Twig-CS-Fixer A PHP tool that lints and automatically fixes Twig coding-standard issues.
  • ludtwig A fast Rust linter and formatter for Twig templates that also validates HTML structure and supports auto-fix.

About

HTML template formatter and linter for Django, Jinja, Twig, Nunjucks, Handlebars, Mustache, Liquid, Go templates, Angular, Tera, Askama and Mako. Formats markup and template syntax together, and lints for accessibility, correctness and style. CLI, language server (LSP), pre-commit hook and VS Code extension.

Topics

Resources

Stars

961 stars

Watchers

8 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages