Should the “for” attribute always come first in an HTML <label> tag for readability?
In an HTML <label>
tag, say there are some custom attributes in the tag and one or more of them alphabetically come before the fo开发者_JAVA技巧r
attribute. Should the for
attribute come first for good style/readability, or does this not matter?
The order of the HTML attributes is irrelevant.
You can try and be consistent for readability, but the DOM parser does not care and once parsed, they do not have any specific order (though in practice they may appear in the order they were assigned).
Personally I would place the for
attribute first as other developers looking at your HTML will look for it (and want to see it first).
Up to you/your team, really.
I personally prefer for
to always come first, as it’s the thing I’m most likely to want to check for correctness, but if you’ve got custom attributes I guess they might be equally as important.
精彩评论