Skip to content Skip to sidebar Skip to footer

Html Attribute Ordering

This may be a subjective question (I hope it isn't)... I develop web designs and applications using Visual Studio and usually Bootstrap. When I drag/drop a CSS file into a HTML doc

Solution 1:

From the HTML 4.01 specification:

Elements may have associated properties, called attributes, which may have values (by default, or set by authors or scripts). Attribute/value pairs appear before the final ">" of an element's start tag. Any number of (legal) attribute value pairs, separated by spaces, may appear in an element's start tag. They may appear in any order.

I can't find anything in the HTML 5 spec which spells out it so clearly, but that rule has not changed.

It is just personal preference.

Solution 2:

For html parsers, the order of attributes does not matter. So it your prefrences. But always they sort and show attributes in alphabetic order. Even you arrange them in youre source code you would see the browser shows them in alphabetic arrange in developer view.

Solution 3:

The HTML5 standard says the order doesn't matter as per the above answers. But if that's the case there will be no need to indent the code as well as a programming language like Java doesn't care about indentation.

The best thing is to follow the conventions already being used in the repository. If you are starting new, the coding standard below provides an order for elements that is being followed by a lot of people.

Attribute order HTML attributes should come in this particular order for easier reading of code.

classid, namedata-*src, for, type, href, valuetitle, altrole, aria-*

Classes make for great reusable components, so they come first. Ids are more specific and should be used sparingly (e.g., for in-page bookmarks), so they come second.

Source: https://codeguide.co/#html-attribute-order

Post a Comment for "Html Attribute Ordering"