Skip to main content

Does the order of attributes matter?

No, the order of attributes in HTML does not matter: the browser processes the element correctly regardless of the order the attributes are written in.


Example:

Both variants are completely equivalent:

html
<img src="photo.jpg" alt="Photo" width="300"> <img width="300" alt="Photo" src="photo.jpg">

The browser will show the same image, because it recognizes attributes by name, not by position.


But there are style recommendations (for readability)

Although the order does not affect how the browser works, professional markup usually follows a logical order of attributes, so the code is readable and consistent.

Example of good practice:

html
<a href="https://example.com" target="_blank" rel="noopener noreferrer" class="link">Link</a>

Recommended sequence:

  1. Main (functional): href, src, type, action;
  2. Behavioral: target, rel, method, role;
  3. Global: id, class, style, title, lang.

Exception: HTML5 "boolean" attributes

For boolean attributes (checked, disabled, required), only their presence matters, not the order. For example:

html
<input required disabled type="text"> <input type="text" disabled required>

Both fields will be both disabled and required.


Summary:

ParameterValue
Does order affect the workNo
How the browser identifies attributesBy name
Are there best practicesYes, for readability and consistency
ExceptionsNone technical, only stylistic

Conclusion: HTML is insensitive to attribute order. What matters is writing them correctly and quoting values; the order is chosen based on readability and the team's standards.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.