Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Is there an official "Best Practice" for ordering attributes in HTML tags? An "HTML Attribute Order Of Precedence".

Hello and thank you for reading. I have always wondered about this and now as I am taking refresher courses I would really like to know so I can apply it to my future development and create good habits.

NOTE: I would call this "HTML Attribute Order Of Precedence". If there is such a thing.

I will create an example for my question:

  • <a href="" class="" target="" title="">Anchor Text</a>

  • <img alt="" title="" src="" /> -

  • <a class="" target="" href="" title="">Anchor Text</a>

  • etc and so forth.

So I hope this simple example illustrates my question and thus my problem. Is there a best practice or should I create my own and stick to it?

I know that in PHP there is a there is a thing called buffering where it parses a given amount of the page before it runs it. It "Looks ahead", so-to-speak, before interpreting the code.

I wonder if browsers do something similar with the HTML. If the browser, or something else?, have to read the HTML but has to go to the end of the tag for the 'src' attribute', then back to the front of the tag for the 'alt' text, then again to the end for the 'title' text, this would undoubtedly lead to a slower performance. However it would be a small performance issue, BUT, an issue none the less.

As an SEO expert and internet marketer, I also think about how the search engines would crawl each link or image. And I would assume that if this so-called "HTML Attribute Order Of Precedence" is a real thing, standardization among browsers would be a thing and thus search engines would likely follow the same standard rules.

So if anyone knows anything about this I would be very grateful for your input, advice, and thoughts, and as always, thank you!

Regards,

DeveloperDan

1 Answer

Steven Parker
Steven Parker
229,732 Points

As far as I know, neither search engines nor browsers care about the order of attributes within an element tag.

The practice I follow is to order then in a way that makes them easiest to read, or to place identification first (id, class) and then the ones most important to the operation (such as "src" for an image, or "href" for a link).

Yeah, this is how I've been doing it. And it looks like you are correct and there is no order. Other sites agree.