Q1 – id for label

Udemy The Web Developer Bootcamp by Colt Steele

Q1

id for labelZhen Tao · Lecture 40 · 2 days ago

Hi,

I have Colt has for the following code “id=” ” for almost all of the labels.

<input type=”checkbox” name=”checkbox” id=”checkbox” />

May I know is it a good practice/ habit or is it a necessary code here?

Zarko — Teaching Assistant · a minute ago

Hello Zhen Tao,

Thanks for the question.

for (on the label element) and id (on the input element) attributes enable us to connect the label element with the corresponding input. Then we can click the label to select the input, and also it’s particularly useful for people with disabilities who are using screen readers, so the input can be correctly interpreted.

Each input in HTML should have its associated label element.

See here to read more: https://stackoverflow.com/a/18432439

Please let me know if you have any more questions.

Leave a comment