diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py
index f455c39c2..330ab10a5 100644
--- a/src/djlint/formatter/indent.py
+++ b/src/djlint/formatter/indent.py
@@ -312,7 +312,7 @@ def fix_handlebars_template_tags(html: str, match: re.Match) -> str:
tmp = re.sub(
re.compile(
- rf"(\s*?)(<(?:{config.indent_html_tags})\b)((?:\"[^\"]*\"|'[^']*'|{{[^}}]*}}|[^'\">{{}}\/])+?)(\s?/?>)",
+ rf"(\s*?)(<(?:{config.indent_html_tags}))\s((?:\"[^\"]*\"|'[^']*'|{{[^}}]*}}|[^'\">{{}}\/])+?)(\s?/?>)",
re.VERBOSE | re.IGNORECASE,
),
func,
diff --git a/tests/test_config/test_max_attribute_length.py b/tests/test_config/test_max_attribute_length.py
index 7a4e1f949..4e58ce9bb 100644
--- a/tests/test_config/test_max_attribute_length.py
+++ b/tests/test_config/test_max_attribute_length.py
@@ -89,6 +89,12 @@
({"max_attribute_length": 10000, "max_line_length": 1000}),
id="longest lines",
),
+ pytest.param(
+ ("\n"),
+ ("\n\n"),
+ ({"max_attribute_length": 3, "custom_html": "[\\w\\-]+"}),
+ id="long tag custom_html",
+ ),
]