Why use this code?

I was doing step 55 of the “learn html by building a cat photo app” i wanted to know why you would use this code

<input id="loving" type="checkbox"> <label for="loving"> Loving </label>

rather than this

<input id="loving" type="checkbox"> Loving

Link: https://www.freecodecamp.org/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-55

Hello.
When editing your post, press ctrl-e, you’ll see how to make code look like

this

And provide link to the challenge,please. Thanks.

1 Like

well, this code doesn’t have correct syntax: no brackets at all, that’s not good for HTML

I guess you have question ‘why use labels’ also.

MDN article contains some explanation:

My apologies I messed up the syntax I fixed it. I will check out the article thank you

got it, so your question was about labels? or something else also?

It was more of, why use one over the other. The article answered this question, using a label allows a greater hitbox and allows screen readers to speak it. I see why I should use the code with label in it, rather than the other one. I appreciate the help!