### Output Example Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/getting-started.md The resulting output after running a reformat command. ```html
``` -------------------------------- ### Install djLint Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/getting-started.md Install the djLint package using common package managers. ```bash pip install djlint ``` ```bash uv tool install djlint ``` ```bash pipx install djlint ``` ```bash brew install djlint ``` ```bash npm i djlint ``` -------------------------------- ### Setup local development environment Source: https://github.com/djlint/djlint/blob/master/README.md Commands to synchronize the project dependencies and execute the test suite using uv. ```bash # install uv first: https://docs.astral.sh/uv/getting-started/installation/ uv sync # run the test suite uv run pytest ``` -------------------------------- ### HTML Template Formatting Examples Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/formatter.md Comparison of raw, standard formatted, and single-attribute-per-line formatted HTML templates. ```html {% load admin_list %} {% load i18n %}

{% if pagination_required %} {% for i in page_range %} {% paginator_number cl i %} {% endfor %} {% endif %} {{ cl.result_count }} {% if cl.result_count == 1 %} {{ cl.opts.verbose_name }} {% else %} {{ cl.opts.verbose_name_plural }} {% endif %} {% if show_all_url %} {% translate 'Show all' %} {% endif %} {% if cl.formset and cl.result_count %} {% endif %}

``` ```html {% load admin_list %} {% load i18n %}

{% if pagination_required %} {% for i in page_range %} {% paginator_number cl i %} {% endfor %} {% endif %} {{ cl.result_count }} {% if cl.result_count == 1 %} {{ cl.opts.verbose_name }} {% else %} {{ cl.opts.verbose_name_plural }} {% endif %} {% if show_all_url %} {% translate 'Show all' %} {% endif %} {% if cl.formset and cl.result_count %} {% endif %}

``` ```html {% load admin_list %} {% load i18n %}

{% if pagination_required %} {% for i in page_range %} {% paginator_number cl i %} {% endfor %} {% endif %} {{ cl.result_count }} {% if cl.result_count == 1 %} {{ cl.opts.verbose_name }} {% else %} {{ cl.opts.verbose_name_plural }} {% endif %} {% if show_all_url %} {% translate 'Show all' %} {% endif %} {% if cl.formset and cl.result_count %} {% endif %}

``` -------------------------------- ### Python Rule Implementation Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Example of a Python module implementing a run() function for custom linting logic. ```python from typing import Any, Dict, List from djlint.settings import Config from djlint.lint import get_line import re def run( rule: Dict[str, Any], config: Config, html: str, filepath: str, line_ends: List[Dict[str, int]], *args: Any, **kwargs: Any, ) -> List[Dict[str, str]]: """ Rule that fails if if the html file contains 'bad'. This is just an example, in reality it's much simpler to do that with "pattern rule". """ errors: List[Dict[str, str]] = [] for match in re.finditer(r"bad", html): errors.append({ "code": rule["name"], "line": get_line(match.start(), line_ends), "match": match.group().strip()[:20], "message": rule["message"], }) return errors ``` -------------------------------- ### Custom Pattern Rule Configuration Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Example of defining a custom rule in .djlint_rules.yaml that triggers on a regex pattern match. ```yaml - rule: name: T001 message: Find Trichotillomania flags: re.DOTALL|re.I patterns: - Trichotillomania ``` -------------------------------- ### Reformat Django Template with djLint Source: https://github.com/djlint/djlint/blob/master/README.md Example of a raw Django template before and after applying the djLint reformat command with attribute splitting. ```django {% block content %}

Latest posts

{%if posts%} {%else%}

No posts yet.

{%endif%}
{% endblock %} ``` ```django {% block content %}

Latest posts

{% if posts %} {% else %}

No posts yet.

{% endif %}
{% endblock %} ``` -------------------------------- ### Custom Python Module Rule Configuration Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Example of defining a custom rule in .djlint_rules.yaml that executes a Python function. ```yaml - rule: name: T001 message: Found the 'bad' word python_module: your_package.your_module ``` -------------------------------- ### H042 Label-Element Association Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Examples of incorrect and correct HTML label-to-input associations for the H042 rule. ```html ``` ```html ``` -------------------------------- ### Override File Extensions in Pre-commit Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/integrations.md Example of overriding default file matching to use Handlebars hooks on .html files. ```yaml repos: - repo: https://github.com/djlint/djLint rev: v{{ djlint_version }} hooks: - id: djlint-reformat-handlebars files: "\\.html" types_or: ["html"] - id: djlint-handlebars files: "\\.html" types_or: ["html"] ``` -------------------------------- ### CLI Help and Output Options Source: https://github.com/djlint/djlint/blob/master/docs/src/_includes/cli.md Displays the available command-line arguments and GitHub-compatible output configuration. ```text [default: 0] --github-output / --no-github-output Output GitHub-compatible formatting. -h, --help Show this message and exit. ``` -------------------------------- ### Lint and format Askama templates via CLI Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/askama.md Run djLint on a specific path using the askama profile. ```bash djlint /path/to/templates --profile=askama ``` -------------------------------- ### Lint and format templates via CLI Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/jinja.md Use the djlint command with the --profile flag to target Jinja-style templates. ```bash djlint /path/to/templates --profile=jinja ``` -------------------------------- ### Configure djLint in djlint.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/configuration.md Define configuration options directly in a djlint.toml or .djlint.toml file. ```toml ``` -------------------------------- ### Lint and format Go templates via CLI Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/golang.md Use the --profile flag to specify the Go template profile when running djLint on a directory. ```bash djlint /path/to/templates --profile=golang ``` -------------------------------- ### Run djLint on templates Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Execute linting on a directory or file, optionally specifying custom extensions or profiles. ```bash djlint /path/to/templates --lint # with custom extensions djlint /path/to/templates -e html.dj --profile=django # or to file djlint /path/to/this.html.j2 --profile=jinja ``` -------------------------------- ### Configure Neovim efm-langserver Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/integrations.md Lua configuration snippets for setting up djLint as a formatter within efm-langserver. ```lua local djlint = { formatCommand = "djlint --reformat --quiet --warn -", formatStdin = true, } ``` ```lua local djlint = { formatCommand = "djlint --reformat --quiet --warn -", formatStdin = true, } require("lspconfig").efm.setup({ filetypes = { "htmldjango" }, init_options = { documentFormatting = true }, settings = { rootMarkers = { ".git/" }, languages = { htmldjango = { djlint }, }, }, }) ``` -------------------------------- ### Lint and format Liquid templates via CLI Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/liquid.md Run the linter on a specific directory using the liquid profile. ```bash djlint /path/to/templates --profile=liquid ``` -------------------------------- ### Configure djLint in pyproject.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/askama.md Set the profile to askama within the project configuration file. ```toml [tool.djlint] profile="askama" ``` -------------------------------- ### Configure djLint in .djlintrc Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/configuration.md Define configuration options using JSON format in a .djlintrc file. ```json { "option": "value" } ``` -------------------------------- ### Lint and format Tera templates via CLI Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/tera.md Use the djlint command with the tera profile to process templates in a specific directory. ```bash djlint /path/to/templates --profile=tera ``` -------------------------------- ### Lint and Format Projects Source: https://github.com/djlint/djlint/blob/master/README.md Commands to lint, check, and reformat project files using djLint. ```bash djlint . --lint ``` ```bash djlint . --check ``` ```bash djlint . --reformat --single-attribute-per-line ``` ```bash djlint . --reformat --single-attribute-per-line --profile=django ``` -------------------------------- ### Lint and format templates via CLI Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/twig.md Use the profile flag to specify the Twig template engine when running djLint from the command line. ```bash djlint /path/to/templates --profile=nunjucks ``` -------------------------------- ### Implement tab switching logic Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/configuration.md JavaScript to handle tab navigation for configuration options. ```javascript document.addEventListener('click', function (e) { if ( e.target.closest('.tabs li a') && e.target.closest('.tabs li a').hasAttribute('tab') ) { var tabLinks = document.querySelectorAll('.tabs li.is-active'); for (var l = 0; l < tabLinks.length; l++) { tabLinks[l].classList.remove('is-active'); } var tabs = document.querySelectorAll('.tab.is-active'); for (var i = 0; i < tabs.length; i++) { tabs[i].classList.remove('is-active'); } var activeBox = document.querySelectorAll('.tab#' + e.target.getAttribute('tab')) for(var y= 0; y < activeBox.length; y++){ activeBox[y].classList.add('is-active'); } var activeTab = document.querySelectorAll('a[tab="' + e.target.getAttribute('tab') + '"]') for(var y= 0; y < activeTab.length; y++){ activeTab[y].parentElement.classList.add('is-active'); } } }); ``` -------------------------------- ### Configure djLint in pyproject.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/jinja.md Set the profile in the project configuration file to apply settings automatically. ```toml [tool.djlint] profile="jinja" ``` -------------------------------- ### Configure djLint in pyproject.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/twig.md Set the profile in the project configuration file to apply settings automatically. ```toml [tool.djlint] profile="nunjucks" ``` -------------------------------- ### Configure Go template profile in pyproject.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/golang.md Set the profile option within the [tool.djlint] section of your project's pyproject.toml file. ```toml [tool.djlint] profile="golang" ``` -------------------------------- ### Reformat files with djLint Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/formatter.md Apply formatting changes to files, optionally including CSS and JS processing. ```bash djlint . --reformat --single-attribute-per-line # how about formatting scripts and styles? djlint . --reformat --single-attribute-per-line --format-css --format-js ``` -------------------------------- ### J004: Use url_for for static assets Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Avoid hardcoding /static/ paths to ensure assets resolve correctly under different URL prefixes. ```html ``` ```html ``` -------------------------------- ### Configure Liquid profile in pyproject.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/liquid.md Set the default profile for djLint within a project configuration file. ```toml [tool.djlint] profile="liquid" ``` -------------------------------- ### Process Stdin Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/getting-started.md Pipe content directly into djLint for linting or formatting. ```bash echo "
" | djlint - ``` ```bash echo "
" | djlint - --reformat ``` -------------------------------- ### Implement search filtering logic Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/configuration.md JavaScript logic to filter configuration options based on user input. ```javascript const hideAll=() => { (document.querySelectorAll('.option') || []).forEach((x) => { x.classList.add('is-hidden') }) } const showAll=() => { (document.querySelectorAll('.option') || []).forEach((x) => { x.classList.remove('is-hidden') }) } var search_data = {{ configuration | dump | safe }}; document.querySelector('#filter').addEventListener('input', (event) => { document.querySelector('#no-matches').classList.add('is-hidden'); if (event.target.value === ''){ showAll() } else { var regex = new RegExp(event.target.value.replaceAll(' ', '.*[ _-].*'), 'gmi'), matches=[] search_data.forEach((obj) => { if (JSON.stringify(obj).match(regex)) { matches.push(obj.name) } if(matches.length > 0){ document.querySelector('#no-matches').classList.add('is-hidden'); (document.querySelectorAll('.option') || []).forEach((x) => { if (matches.includes(x.getAttribute('data-name'))){ x.classList.remove('is-hidden') } else { x.classList.add('is-hidden') } })} else { hideAll(); document.querySelector('#no-matches').classList.remove('is-hidden'); } }) } }) ``` -------------------------------- ### Lint Angular Templates via Command Line Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/angular.md Use the djlint command with the Angular profile to lint your template files. Replace '/path/to/templates' with the actual path to your Angular templates. ```bash djlint /path/to/templates --profile=angular ``` -------------------------------- ### Allow Empty Input Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/getting-started.md Prevent exit code 2 when no templates are found in the specified path. ```bash djlint /path/to/templates --lint --allow-empty-input ``` -------------------------------- ### Configure Pre-commit for Django Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/integrations.md Standard configuration for using djLint as a pre-commit hook for Django projects. ```yaml repos: - repo: https://github.com/djlint/djLint rev: v{{ djlint_version }} hooks: - id: djlint-reformat-django - id: djlint-django ``` -------------------------------- ### Check formatting with djLint Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/formatter.md Use the --check flag to review potential formatting changes without modifying files. ```bash djlint . --check ``` -------------------------------- ### Lint Files via CLI Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/getting-started.md Run linting checks on specific directories or files. ```bash djlint /path/to/templates --lint ``` ```bash djlint /path/to/this.mustache --lint ``` -------------------------------- ### Include or ignore specific rules Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use the --include and --ignore flags to explicitly enable or disable specific linting rules via the command line. ```bash djlint . --lint --include=H017,H035 --ignore=H013,H015 ``` -------------------------------- ### Use Jinja url_for pattern (J018) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use url_for() to generate internal links dynamically to prevent broken paths. ```html Login ``` ```html Login ``` -------------------------------- ### Replace javascript: URLs (H019) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Avoid javascript: pseudo-protocols in href attributes; use event handlers instead. ```html Open popup ``` ```html Open popup ``` -------------------------------- ### Configure Tera profile in pyproject.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/tera.md Set the profile to tera within the [tool.djlint] section of your pyproject.toml file. ```toml [tool.djlint] profile="tera" ``` -------------------------------- ### Add djLint badge to Markdown Source: https://github.com/djlint/djlint/blob/master/README.md Use this snippet to display a djLint style badge in a Markdown readme file. ```md [![Code style: djlint](https://img.shields.io/badge/html%20style-djlint-blue.svg)](https://djlint.com) ``` -------------------------------- ### Not Recommended Conditional Attributes (with formatting) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/best-practices.md This pattern is not recommended when `format_attribute_template_tags` is enabled, as djLint's formatting can introduce unwanted line breaks and spaces. ```html ``` -------------------------------- ### Configure djLint for Angular in pyproject.toml Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/languages/angular.md Set the 'angular' profile in your pyproject.toml file to configure djLint for Angular projects. This ensures djLint uses the correct rules for Angular templates. ```toml [tool.djlint] profile="angular" ``` -------------------------------- ### Use Django url template tag (D018) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use the {% url %} pattern instead of hardcoded paths to ensure links remain valid when routes change. ```html Login ``` ```html Login ``` -------------------------------- ### Specify Stdin Filename Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/getting-started.md Provide a virtual filename for piped content to ensure correct configuration matching. ```bash echo "
" | djlint - --stdin-filename templates/index.html ``` -------------------------------- ### Ignore code blocks with djLint tags Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/ignoring-code.md Wrap code in specific comment tags to prevent djLint from processing the enclosed content. ```html ``` ```html {# djlint:off #} {# djlint:on #} ``` ```html {% comment %} djlint:off {% endcomment %} {% comment %} djlint:on {% endcomment %} ``` ```html {{ /* djlint:off */ }} {{ /* djlint:on */ }} ``` ```html {{!-- djlint:off --}} {{!-- djlint:on --}} ``` -------------------------------- ### Add a meta description (H030) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Include a meta description tag for better SEO and link previews. This rule only applies to complete HTML documents. ```html Home Welcome ``` ```html Home Welcome ``` -------------------------------- ### Add djLint badge to reStructuredText Source: https://github.com/djlint/djlint/blob/master/README.md Use this snippet to display a djLint style badge in a reStructuredText readme file. ```rst .. image:: https://img.shields.io/badge/html%20style-djlint-blue.svg :target: https://djlint.com ``` -------------------------------- ### Add meta keywords (H031) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Include meta keywords for legacy search tools. This rule is disabled by default and requires --include=H031. ```html Home ``` ```html Home ``` -------------------------------- ### D004: Django Static URL Pattern Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Enforces the use of the {% static %} tag instead of hardcoded paths to support dynamic asset management. ```html ``` ```html ``` -------------------------------- ### Formatted Conditional Attributes (Not Recommended Pattern) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/best-practices.md This shows how the non-recommended pattern for conditional attributes can be formatted by djLint, potentially breaking code due to added whitespace. ```html ``` -------------------------------- ### Avoid presentational
tags (H036) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Replace forced line breaks with block elements and CSS margins to maintain semantic structure and accessibility. ```html

Shipping is free.
Delivery takes 3 days.

``` ```html

Shipping is free.

Delivery takes 3 days.

``` -------------------------------- ### H006: Require height and width on img tags Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Define image dimensions to prevent layout shifts during page loading. Enable this rule with --include=H006. ```html Cat ``` ```html Cat ``` -------------------------------- ### H010: Use lowercase attribute names Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Lowercase attribute names ensure compatibility and consistent text searching across templates. ```html Cat ``` ```html Cat ``` -------------------------------- ### Enforce self-closing void tags (H017) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use XHTML-style self-closing slashes for void elements. Enable with --include=H017. ```html
``` ```html
``` -------------------------------- ### Use HTTPS for external links (H022) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure all external links use HTTPS to prevent interception and tampering. ```html Example ``` ```html Example ``` -------------------------------- ### H007: Require DOCTYPE declaration Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure a DOCTYPE is present before the html tag to avoid quirks mode rendering. ```html ``` ```html ``` -------------------------------- ### T001: Template Variable Spacing Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensures template variables are wrapped in whitespace for better readability and grep consistency. ```html {{user.name}} ``` ```html {{ user.name }} ``` -------------------------------- ### Remove extra blank lines (H014) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Avoid excessive blank lines to reduce template bloat and noisy diffs. ```html
one

two

``` ```html
one

two

``` -------------------------------- ### Enforce plain void tag endings (H018) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use plain > endings for void elements to follow the HTML living standard. Enable with --include=H018. ```html
``` ```html
``` -------------------------------- ### Use lowercase form method values (H029) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use lowercase keywords for form methods to ensure consistency and compatibility with strict validators. ```html
``` ```html
``` -------------------------------- ### Fix unclosed template strings (T027) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure all strings within template tags are properly closed to avoid parsing errors. ```html {% trans "Welcome %} ``` ```html {% trans "Welcome" %} ``` -------------------------------- ### Identify unclosed template tags (T039) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Catch syntax errors where template tags are missing their closing delimiters. ```django

{{ user.name }

``` ```django

{{ user.name }}

``` -------------------------------- ### Not Recommended Spaces Around Conditional Attributes Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/best-practices.md This pattern is not recommended as djLint removes whitespace inside conditional statements, potentially leading to unexpected formatting. ```html
content
``` -------------------------------- ### H009: Use lowercase tag names Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use lowercase for all HTML tags to ensure compatibility with XHTML/XML and improve searchability. ```html

Welcome

``` ```html

Welcome

``` -------------------------------- ### Validate template name in extends/include (T040) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure template tags like extends or include contain a valid, non-empty template name. ```django {% extends "" %} ``` ```django {% extends "base.html" %} ``` -------------------------------- ### Avoid inline styles (H021) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Move inline styles to CSS classes to improve maintainability and comply with Content Security Policies. ```html
Wrong username or password.
``` ```html
Wrong username or password.
``` -------------------------------- ### Correct template tag delimiters (T034) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure template tags are closed with %} instead of }% to avoid syntax errors or raw text leakage. ```html {% include "footer.html" %} ``` ```html {% include "footer.html" %} ``` -------------------------------- ### Ignore specific linter rules Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/ignoring-code.md Specify rule codes within the opening tag to disable only those rules for the block. ```html {# djlint:off H025,H026 #}

{# djlint:on #}

{% comment %} djlint:off H025 {% endcomment %}

{% comment %} djlint:on {% endcomment %} {{!-- djlint:off H025 --}}

{{!-- djlint:on --}} {{ /* djlint:off H025 */ }}

{{ /* djlint:on */ }} ``` -------------------------------- ### Recommended Spaces Around Conditional Attributes Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/best-practices.md djLint removes whitespace inside conditional statements. This pattern is recommended for cleaner formatting. ```html

content
``` -------------------------------- ### H013: Require alt attribute on img tags Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Provide alt text for images to satisfy accessibility requirements and improve user experience when images fail to load. ```html ``` ```html A sleeping cat ``` -------------------------------- ### Recommended Spaceless Conditional Attributes Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/best-practices.md When `format_attribute_template_tags` is enabled, use spaceless tags within conditional attributes to prevent unwanted spaces. This pattern is recommended. ```html ``` -------------------------------- ### Enforce self-closing meta tags (H035) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use this rule to ensure meta tags are XHTML-compatible by including a trailing slash. ```html ``` ```html ``` -------------------------------- ### Use literal characters instead of entity references (H023) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use literal UTF-8 characters instead of entity references for better readability and to avoid rendering errors. ```html

Dates 1900 — 2000

``` ```html

Dates 1900 — 2000

``` -------------------------------- ### Validate matching block tags (T038) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure all template block tags have corresponding closing tags to prevent template syntax errors. ```django {% if user.is_authenticated %}

Welcome back!

``` ```django {% if user.is_authenticated %}

Welcome back!

{% endif %} ``` -------------------------------- ### H008: Use double quotes for attributes Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Standardize on double quotes for attribute values to improve consistency and avoid issues with apostrophes. ```html
``` ```html
``` -------------------------------- ### Add line breaks after heading tags (H015) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure block-level elements follow headings to maintain document structure and clean diffs. ```html

Heading

Intro text.

``` ```html

Heading

Intro text.

``` -------------------------------- ### Remove empty id and class attributes (H026) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Remove empty id or class attributes as they serve no purpose and can indicate template bugs. ```html
content
``` ```html
content
``` -------------------------------- ### H005: Require lang attribute on html tag Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Include a lang attribute on the html tag to support screen readers and browser translation features. ```html ``` ```html ``` -------------------------------- ### Remove extra whitespace in template tags (T032) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Avoid unnecessary spaces between template tag arguments to maintain clean diffs and consistent formatting. ```html {% static 'css/style.css' %} ``` ```html {% static 'css/style.css' %} ``` -------------------------------- ### Remove empty tag pairs (H020) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Avoid empty tags that create unnecessary DOM nodes. Tags with attributes or specific semantic elements are exempt. ```html

Saved.

``` ```html

Saved.

``` -------------------------------- ### T002: Double Quotes in Tags Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Standardizes the use of double quotes within template tags to ensure consistency across the codebase. ```html {% extends 'base.html' %} ``` ```html {% extends "base.html" %} ``` -------------------------------- ### T003: Named Endblock Tags Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Requires endblock tags to include the block name to prevent nesting errors and improve readability. ```html {% block content %}

hello

{% endblock %} ``` ```html {% block content %}

hello

{% endblock content %} ``` -------------------------------- ### Require title tag in HTML (H016) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Every complete HTML document must include a title element for accessibility and SEO. ```html Content ``` ```html My page Content ``` -------------------------------- ### Fix orphan tags (H025) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure all tags are properly closed to prevent browser parsing errors and layout issues. ```html

Hello

``` ```html

Hello

``` -------------------------------- ### Use spaceless tags in attributes (T028) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Use whitespace-control tags to prevent stray spaces in rendered URLs within attributes. This rule does not apply to the Django profile. ```html ``` ```html ``` -------------------------------- ### Remove extra whitespace in form action (H033) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Ensure form action values do not contain leading or trailing whitespace to prevent broken URLs. ```html
``` ```html
``` -------------------------------- ### Detect duplicate HTML attributes (H037) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Prevent bugs caused by duplicate attributes which browsers silently ignore after the first occurrence. ```html
...
``` ```html
...
``` -------------------------------- ### Enforce tag closure within the same block (H041) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Keep HTML tags opened and closed within the same template block to ensure child templates can override blocks safely. ```django {% block content %}
{% endblock content %} {% block footer %}
{% endblock footer %} ``` ```django {% block content %}
{% endblock content %} {% block footer %} {% endblock footer %} ``` -------------------------------- ### H012: Remove spaces around attribute equals sign Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Keep attribute assignments contiguous to ensure reliable parsing and text tool compatibility. ```html
``` ```html
``` -------------------------------- ### Omit type attribute on scripts and styles (H024) Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Remove the type attribute from script and style tags as they are unnecessary in HTML5. ```html ``` -------------------------------- ### H011: Quote attribute values Source: https://github.com/djlint/djlint/blob/master/docs/src/docs/linter.md Always quote attribute values to prevent parsing errors caused by whitespace or special characters. ```html
``` ```html
``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.