Skip to content

Linter Rule: No whitespace around = in HTML attributes

Rule: html-attribute-equals-spacing

Description

Disallow whitespace before or after the equals sign (=) for attribute values in HTML. Attributes must follow the canonical format (name="value") with no spaces between the attribute name, the equals sign, or the opening quote.

Rationale

Extra whitespace around the = in HTML attribute assignments is unnecessary, inconsistent, and not idiomatic. While browsers are usually forgiving, it can lead to confusing diffs, poor formatting, or inconsistent parsing in tools.

Examples

✅ Good

erb
<div class="container"></div>
<img src="/logo.png" alt="Logo">
<input type="text" value="<%= @value %>">

🚫 Bad

erb
<div class ="container"></div>
Remove whitespace before `=` in HTML attribute (html-attribute-equals-spacing)
<img src= "/logo.png" alt="Logo">
Remove whitespace after `=` in HTML attribute (html-attribute-equals-spacing)
<input type = "text">
Remove whitespace after `=` in HTML attribute (html-attribute-equals-spacing)
Remove whitespace before `=` in HTML attribute (html-attribute-equals-spacing)

References

-

Released under the MIT License.