<form> <input - semantics

What difference does the sequence make within input of a form?

 <input  value='Davie' type='text' name='username' />
 <input  type='text' name='username' value='Davie' />
 <input name='username'  type='text' value='Davie' />

They all seem to produce the same result.

Thank you,

Hey @robbiejfrye, I formatted your code. Go ahead and check out this post as a reference on how to do this.

Nothing. The order of the attributes is irrelevant in this situation.


Thanks for the quick response @stevencopeland

Thanks for the link to how to share code within forums.

In an obsessive world, I’m not quite sure if I’m happy that it doesn’t matter.

When I have 3 months in I’ll reassess.

Thank you,

It doesn’t matter, but it could.

What I’d personally advise, is to keep it consistent. Pick one of the three, and stick to it.

It’ll be much easier to navigate through your code and quickly make changes when needed, without having to go through each line, every time, looking for that specific attribute. Especially when having to go back to your code months/years after last touching it.

Also, it could matter, if you end up sharing your code with other developers. If they know that the attribute value= always comes last, it’ll simply make their life easier. Sure, it’s not that big of a deal, but clean code, code that’s consistent, and that makes sense, is nicer and easier to navigate.

This applies not only to HTML (although HTML is less “regulated”, I’d say), but also to CSS and programming languages. This is one of the reasons we have frameworks. Consistency & standards recommandations make our life and the life of others much easier.

Then it’s up to you to apply this, or not.

1 Like