Does the order of attributes matter?

In the explanation of Adding a Label, we found <input type=“text” name=“x” id=“x”>. In the explanation of Password Input, we found <input type=“password” id=“x” name=“x”>. While in “Number Input,” we found <input id=“x” name=“x” type=“number” step=“x”>

My question is, why in Adding a Label, the name attribute comes before the id attribute, different from in Password Input which the name attribute comes after the id attribute and also their structure of the use type, name, id different from the Number Input structure?

Structurally, is it that way? Thanks!

1 Like

attribute order is irrelevant, you could use any order you like

15 Likes

Hi,
Although I understand that the attribute order is irrelevant in terms of execution order and rendering on the HTML page. Yet in previous lessons we are taught about readability of the code and common practice. Surely there is some guideline on the order of attributes ? Or at least an order to agree on.
Type / Name / ID / etc ?

Thank you for any extra clarification.

7 Likes

yes, unfortunately, there is no guidance, so you choice your own order if you work alone, or choice an order for the attributes when working in a team and then sticking to them

8 Likes

After reading through the comments I understand the the attributes and values perfectly fine, as well as per the comments that the order does not matter, why doesn’t the lesson make this clear and marks us wrong if we follow the example to put “type / id / name” in that order instead of the “id / type / name”?

1 Like

order of attributes is not relevant. However, being consisted within one project is better practice.

3 Likes

“‘label’ tag before ‘input’, or does it matter?”

Hi,

newbie here. Really loving the course so far. In my head it would make more sense to write the input first, then label it.

Does it matter, or is this a coding convention I should get used to now, that will make more sense as I progress?

Many thanks :pray:

so far i know it doesn’t matter, have you googled it?

I’m a newbie too, but as I understood this moment — if you put <label> after <input>, this will be rendered in that order too.

That means you will get label on your site after the input field, which is probably not what you want

2 Likes

Thank you , I was going to ask the same

order of attribute won’t matter in every case