Why am I using label for tags?

https://www.codecademy.com/paths/web-development/tracks/learn-html-web-dev-path/modules/learn-html-forms/projects/form-a-story

I’m working on the form a story project. Task 13.

Up until this point, I thought <label for=Example>Example</label>was used to link it to the inputs id.

So <label for="example"></label> <input id=example type=radio>

However, it seems that I can make the for anything and it will still appear correctly.

Such as: <label for="example"></label> <input id=Yes type=radio>

Hoping someone can refresh me, why exactly are we using the for= attribute with labels?

Thanks :slight_smile:

Accessibility. Not everyone in the world has perfect vision. And given how important the internet is today, even people with poor vision should be able to use your website.

Accessibility tools like screen readers need to know which label is associated with which input field.

2 Likes

Perfect! Thank you very much!!