Label ids for forms

What will happen if the label’s id isn’t the same as the input’s id? Would that change anything because it doesn’t seem to change anything visually.

1 Like


It would be useful to provide some context by way of an example, however I assume you are asking about labels for HTML form elements?

The id of a form element is used to link it to it’s label on the page. Consider this: you have a username field with a label that says “Username:” adjacent to it.

<label for="username">Username:</label>
<input type="text" id="username" name="username">

In this example, clicking on the area of the screen that says “Username:” will highlight the form field. They are linked by using the same value for the label for="" and the input id="" bits.

“Un-linking” the label from the input field doesn’t break the form at all, but is probably less user friendly.

1 Like

Thank you for the answer. I was asking about the HTML form elements. I guess when I was playing around and change the id to something random I didn’t notice that clicking on the label didn’t highlight the input box.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.