valid order for attributes of input type tag

Already been answered, but my full and expanded answer is:

  • There is no predefined order for the attributes in terms of passing w3c validation… it’s completely up to you.

However, you should introduce your own standard and stick to it.

If there are multiple coders working on the application they should all stick to the same standard.

If you are a team leader, web-dev business owner, manager, etc, it is your responsibility to encourage (and enforce) a culture that uses this standard.

When doing code reviews the attribute order should be checked, and anything that fails you should make the coder responsible fix it up… they’ll only muck it up once or twice if they know they’ll have to rewrite their code!!!

And why all this fuss and bother over attribute order?

  • This will increase code development and debugging speed.
  • It makes code more readable
  • It encourages the coders (or you) to pay attention to the little details
  • It helps to fosters an environment of “accountability for your own code”

My personal preference is:

  1. type (so you can instantly see what it is)
  2. id
  3. class (I like to keep 2 and 3 together as they are the most common js/jQuery selectors)
  4. name
  5. value (I like to keep 4 and 5 next to each other so you can quickly reference what input it is and it’s value).
  6. All others (like checked, max-size, etc)
  7. style
  8. tabindex (I like 7 and 8 to be at the end as it’s “non-relevant”, in terms of the actual functionality, they are more styling/usability stuff, keep ’em out of the way!

Leave a Comment