Skip to content

Configuration

Configuration goes in your project’s pyproject.toml, a djlint.toml or .djlint.toml, or a .djlintrc. Command line options override the config file, but a flag can only turn an option on, so it can’t turn off a switch the config file sets. The project’s settings override a global config file given with --configuration, unless --prefer-configuration is set.

djLint looks for these files upward from the first path it checks (for -, from the folder of --stdin-filename, or from the current directory without it). It stops at the first folder that holds a djlint.toml, a .djlint.toml, a .djlintrc, a .djlint_rules.yaml or a pyproject.toml with [tool.djlint], and never goes past the root of a repository (a folder with a .git folder or file, or a .hg folder). A pyproject.toml without djLint settings doesn’t stop it, so a package in a monorepo with its own pyproject.toml gets the settings of the repository. djLint reads only the folder it stops at: [tool.djlint] in its pyproject.toml if that table sets anything, otherwise its djlint.toml or .djlint.toml, otherwise its .djlintrc, and warns about the ones there that it doesn’t read.

Where neither the command line nor the configuration sets indent or max_line_length, djLint takes indent_size or max_line_length from .editorconfig files, as editors do: each file gets them by its own path, the nearest .editorconfig wins and the ones above it fill in, up to one with root = true or the project root.

The format for pyproject.toml is toml.

[tool.djlint]
profile = "django"
ignore = ["H014", "H015"]

The format for djlint.toml and .djlint.toml is toml.

profile = "django"
ignore = ["H014", "H015"]

The format for .djlintrc is json.

{ "profile": "django", "ignore": ["H014", "H015"] }

Options that take several values, such as ignore, take a list. A comma-separated string such as "H014,H015" works too, and is what djLint before 1.41 needs.

From version 1.51, djLint warns about a setting or a rule code it doesn’t know, and names the closest one it does.

allow_empty_input

since 1.44.0 formatter linter --allow-empty-input

Default: false

Exit with 0 instead of 2 when the given paths match no files at all. Files that were found and then skipped by exclude, extend_exclude, use_gitignore or require_pragma already exit with 0.

allow_empty_input=true

blank_line_after_tag

since 0.4.2 formatter --blank-line-after-tag

Default: none

Template tags to follow with a blank line, such as load and extends. A group of them in a row gets one after the last, and none is added at the end of a block.

blank_line_after_tag=["load", "extends", "include"]

blank_line_before_tag

since 1.8.0 formatter --blank-line-before-tag

Default: none

Template tags to precede with a blank line, such as load and extends. A group of them in a row gets one before the first, and none is added at the start of a file or block.

blank_line_before_tag=["load", "extends", "include"]

close_void_tags

since 1.26.0 formatter linter --close-void-tags

Default: false

Close known void tags with a slash, so <img> becomes <img />. H018, which asks for the opposite, is not reported under it.

close_void_tags=true

configuration

since 1.13.0 formatter linter --configuration

A global config file, a pyproject.toml, djlint.toml or .djlintrc, such as one in your home folder. The project’s own config file wins where both set an option, unless prefer_configuration is on.

Terminal window
--configuration ~/.djlintrc

custom_blocks

since 0.3.5 formatter --custom-blocks

Default: none

Names of custom template blocks to indent, such as toc for {% toc %}...{% endtoc %}.

custom_blocks=["toc", "example"]

custom_html

since 0.7.0 formatter --custom-html

Default: none

Names of custom HTML tags to indent, such as mjml or simple-greeting. A name can be a regex, as in mj-\w+.

custom_html=["mjml", "simple-greeting", 'mj-\w+']

exclude

since 0.4.0 linter formatter --exclude

Default: "__pypackages__,_build,_site,.bzr,.direnv,.eggs,.git,.git-rewrite,.hg,.nox,.svn,.tox,.venv,build,dist,htmlcov,node_modules,site-packages,venv"

Paths to skip, in place of the default list. Each entry is a regular expression matched against whole folder or file names in the path relative to the project root or to the folder being checked, such as vendor or templates/legacy, so *.min.html is written .*\.min\.html.

exclude=[".venv", "venv", "build"]

extend_exclude

since 0.4.0 linter formatter --extend-exclude

Default: none

Paths to skip on top of exclude, or of the default list when exclude isn’t set, as regular expressions like those of exclude.

extend_exclude=[".custom"]

extension

since 0.0.5 linter formatter --extension

Default: "html"

Extension of the files to look for in folders. It takes one extension; a file given by name is checked whatever its extension.

extension="html.dj"

files

since 1.14.0 linter formatter

Default: none

Paths to check instead of the ones on the command line, which must then be -, as for stdin. With --stdin-filename, - means stdin regardless.

[tool.djlint]
files=["index.html"]

format_attribute_js_json

since 1.37.0 formatter --format-attribute-js-json

Default: false

Also format JavaScript and JSON in attributes such as onclick and x-data, the ones format_attribute_js_json_pattern names. An object with fewer properties than format_attribute_js_json_min_props stays on one line.

format_attribute_js_json=true

format_attribute_js_json_min_props

since 1.37.0 formatter --format-attribute-js-json-min-props

Default: 2

Format an object only when it has at least this many properties. One with fewer stays on one line.

format_attribute_js_json_min_props=3

format_attribute_js_json_pattern

since 1.37.0 formatter --format-attribute-js-json-pattern

Default: "^(?:on[a-z]+|x-[a-z\\-]+|@[a-z\\-]+|:[a-z\\-]+|v-[a-z\\-]+|\\([a-z\\-]+\\)|\\[[a-z\\-]+\\]|\\*ng[A-Z][a-zA-Z]*|[a-z\\-]+\\.(bind|delegate|call|trigger))$"

Regex for the names of the attributes to format as JavaScript or JSON. The default takes on* event handlers and the bindings of Alpine, Vue, Angular and Aurelia.

format_attribute_js_json_pattern="^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"

format_attribute_template_tags

since 0.6.7 formatter --format-attribute-template-tags

Default: false

Format template syntax inside tag attributes.

format_attribute_template_tags=true

format_css

since 1.9.0 formatter --format-css

Default: false

Also format the contents of <style> tags, with css-beautify. Template syntax inside them is not fully supported.

indent_size in the css table, or --indent-css on the command line, sets the indent inside <style> tags, 4 by default. The table takes the other css-beautify options too.

[tool.djlint]
format_css=true
[tool.djlint.css]
indent_size=5

format_js

since 1.9.0 formatter --format-js

Default: false

Also format JavaScript and JSON in <script> tags, with js-beautify. A script whose type is neither JavaScript nor JSON, such as a client-side template in text/template, is left as written. Template syntax inside them is not fully supported.

indent_size in the js table, or --indent-js on the command line, sets the indent inside <script> tags, 4 by default. The table takes the other js-beautify options too.

[tool.djlint]
format_js=true
[tool.djlint.js]
indent_size=5

github_output

since 1.37.0 formatter linter --github-output

Default: none

Print the results as GitHub Actions annotations. It’s on by default inside GitHub Actions, and --no-github-output turns it off. See GitHub Actions.

Terminal window
--github-output

ignore

since 0.1.5 linter --ignore

Default: none

Linter codes to skip.

ignore=["H014", "H015"]

ignore_blocks

since 1.24.0 formatter --ignore-blocks

Default: none

Template blocks that do not indent their contents. Their children are treated as siblings of the block and indented accordingly.

ignore_blocks=["raw", "example"]

ignore_case

since 1.23.0 formatter linter --ignore-case

Default: false

Do not fix the case of known HTML tags. H009 and H010 are not reported under it.

[tool.djlint]
ignore_case=true

include

since 1.20.0 linter --include

Default: none

Linter codes to turn on that are off by default or that the profile leaves out.

include=["H014", "H015"]

indent

since 0.3.5 formatter --indent

Default: 4

Spaces per indent level. When it isn’t set, djLint takes the indent_size that .editorconfig gives the file, if any.

indent=3

keep_br_inline

since 1.45.0 formatter --keep-br-inline

Default: false

Keep <br> on the line of the text it breaks, rather than giving it a line of its own. <hr>, which renders as a rule below the preceding content, is unaffected.

keep_br_inline=true

line_break_after_multiline_tag

since 1.27.0 formatter --line-break-after-multiline-tag

Default: false

When a tag’s attributes are spread over lines, start its content on a new line.

line_break_after_multiline_tag=true

linter_output_format

since 0.6.7 linter --linter-output-format

Default: "{code} {line} {message} {match}"

The layout of each lint message, from {filename}, {line}, {end}, {code}, {message} and {match}. Without {filename}, the output is grouped by file and each group gets a header.

linter_output_format="{filename}:{line}: {code} {message} {match}"

max_attribute_length

since 0.5.8 formatter --max-attribute-length

Default: 70

The formatter spreads a tag’s attributes over lines once they are longer than this.

max_attribute_length=10

max_blank_lines

since 1.31.0 formatter --max-blank-lines

Default: 0

Keep at most this many blank lines in a row, so 0 removes them. It has no effect with preserve_blank_lines.

max_blank_lines=5

max_line_length

since 0.5.7 formatter --max-line-length

Default: 120

The formatter joins some HTML and template tags onto one line only when the line fits within this length. When it isn’t set, djLint takes the max_line_length that .editorconfig gives the file, if any.

max_line_length=100

name_endblocks

since 1.45.0 formatter --name-endblocks

Default: false

Write the block’s name into the {% endblock %} that closes it, where the block is written across lines. This is what T003 asks for.

name_endblocks=true

no_entity_formatting

since 1.45.0 formatter --no-entity-formatting

Default: false

Do not rewrite an entity reference as the character it names, so &copy; is left as written rather than becoming ©. The entities that carry syntax, and the invisible ones, are never rewritten either way. H023 still reports an entity under it; add H023 to ignore to keep entities.

no_entity_formatting=true

no_function_formatting

since 1.30.2 formatter --no-function-formatting

Default: false

Do not format the arguments of function calls inside {{ }}.

no_function_formatting=true

no_indent_inner_html

since 1.45.0 formatter --no-indent-inner-html

Default: false

Do not indent <head> and <body> inside <html>, which is how the built-in VS Code HTML formatter lays a document out.

no_indent_inner_html=true

no_line_after_yaml

since 1.29.0 formatter --no-line-after-yaml

Default: false

Do not add a blank line after YAML front matter.

no_line_after_yaml=true

no_set_formatting

since 1.30.2 formatter --no-set-formatting

Default: false

Do not format the contents of {% set %} tags.

no_set_formatting=true

per_file_ignores

since 1.7.0 linter --per-file-ignores

Default: none

Linter codes to skip in the files whose path matches a regex. In a config file the key is per-file-ignores, with hyphens.

[tool.djlint.per-file-ignores]
"file.html"= "H026,H025"
"file_two.html"="H001"

prefer_configuration

since 1.45.0 formatter linter --prefer-configuration

Default: false

Let the file named by --configuration override the project’s own config file, which wins by default where both set the same option. Command line only, since it decides how the config files themselves are read.

Terminal window
--prefer-configuration

preserve_blank_lines

since 1.3.0 formatter --preserve-blank-lines

Default: false

Keep blank lines where possible. Useful for templates other than HTML, where blank lines are intentional.

preserve_blank_lines=true

preserve_class_newlines

since 1.39.0 formatter --preserve-class-newlines

Default: false

Keep the line breaks in class attributes written across lines.

preserve_class_newlines=true

preserve_leading_space

since 1.2.0 formatter --preserve-leading-space

Default: false

Keep the leading spaces of text lines where possible. Useful for templates other than HTML, where the indent of text is intentional.

preserve_leading_space=true

profile

since 0.4.5 linter formatter --profile

Default: none

The template language. It decides which linter rules run and how the template syntax is formatted: in handlebars, for example, there are no spaces inside {{#if}} tags.

Without a profile, djLint formats the template syntax of every language, as all does, and lints with the rules of html.

Options:

  • html
  • django
  • jinja
  • nunjucks (for nunjucks and twig)
  • handlebars (for handlebars and mustache)
  • liquid (shopify, jekyll, eleventy)
  • golang (go templates; hugo, helm)
  • angular
  • tera (also for zola; use jinja for minijinja)
  • askama (jinja-style templates in rust; rust expressions are never reformatted)
  • mako (control lines and ## comments are kept as written)
  • all (every template language at once)
profile="django"

quiet

since 0.0.9 formatter linter --quiet

Default: false

Do not print diffs, the progress bar or the summary.

quiet=true

quote_style

since 1.45.0 formatter linter --quote-style

Default: "double"

Quotes for strings inside template tags, double or single. T002 asks for the same quotes, and the formatter uses them in conditions such as {% if x == "a" %}, so one file does not spell the same string both ways. Quoting of HTML attributes is left to H008.

quote_style="single"

require_pragma

since 0.5.8 formatter linter --require-pragma

Default: false

Only format or lint files that start with a djlint:on comment. It can be an HTML comment or one in the template language of the profile, and without a profile, one in any of them.

<!-- djlint:on -->
{# djlint:on #}
{% comment %} djlint:on {% endcomment %}
{{ /* djlint:on */ }}
{{!-- djlint:on --}}
require_pragma=true

rules

since 1.41.0 formatter linter --rules

A custom rules file in the .djlint_rules.yaml format, read instead of the one in the project root.

Terminal window
--rules ../shared/.djlint_rules.yaml

sarif

since 1.46.0 formatter linter --sarif

Default: false

Print the findings as a SARIF 2.1.0 document, for GitHub code scanning and other tools. See GitHub Actions.

Terminal window
--sarif

single_attribute_per_line

since 1.40.0 formatter --single-attribute-per-line

Default: false

When an opening tag wraps, put the tag name, each attribute and the closing bracket on separate lines.

single_attribute_per_line=true

sort_attributes

since 1.45.0 formatter --sort-attributes

Default: false

Sort attributes by name, with id first and class second. A tag whose attributes are guarded by a template tag keeps the order it was written in, since moving one out of its branch would change the page.

sort_attributes=true

sort_load_tags

since 1.47.0 formatter --sort-load-tags

Default: false

Sort the libraries in {% load %} tags and drop the ones written twice, so {% load static i18n %} becomes {% load i18n static %}. In {% load a b from library %} the names before from are sorted. Where two libraries define a tag or filter of the same name, the one loaded last wins, so sorting can change which one the template uses.

sort_load_tags=true

statistics

since 1.16.0 linter --statistics

Default: false

After linting, print how many times each code was found.

Terminal window
--statistics

stdin_filename

since 1.43.0 formatter linter --stdin-filename

Default: "-"

Path that stands for stdin in messages and when matching exclude and per-file-ignores.

Terminal window
--stdin-filename templates/index.html

use_gitignore

since 0.5.9 linter formatter --use-gitignore

Default: false

Also skip the paths that the .gitignore in the project root lists.

use_gitignore=true

version

since 0.3.9 formatter linter --version

Show the version and exit.

Terminal window
--version

warn

since 0.7.6 formatter linter --warn

Default: false

Exit with 0 instead of 1 when there are lint errors or files to reformat.

Terminal window
--warn