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

51 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.

17 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

14 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”?

3 Likes

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

6 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

5 Likes

Thank you , I was going to ask the same

order of attribute won’t matter in every case

Hello,
So I also had this question due to my answer being counted wrong and I was wondering if anyone could let me know if it is just a bug or am I actually doing something wrong?

Mine (Incorrect)
<input type="password" name"user-pw" id="user-pw">

Codecademy (Correct)
<input id="user-pw" type="password" name="user-pw">

Any help would be greatly appreciated.

Codecademy might be stricter due to having to validate the user/exercise code

Ah. I see. That makes sense; I stared at my computer for so long trying to figure it out!

Thank you very much for your quick response.
Have a good day.

You’re missing = in name"user-pw"

4 Likes