Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Stefan Cutajar
Stefan Cutajar
7,747 Points

Should check boxes be used only with label elements?

Hi, After completing Js and the DOM course I've decided to try to write a basic to do app on my own for practice. I am thinking of making ul list and a check box next to each item so I can strike out the done to dos. Is this a good idea to add check boxes to a li element or they are meant to be with label elements?

2 Answers

Steven Parker
Steven Parker
231,072 Points

If the list item contains some text in addition to the check box, that text could be enclosed in a label element. The advantage of the label is that when properly associated with the box (using "for"), you can activate it by clicking on the words as well as the box.

Stefan Cutajar
Stefan Cutajar
7,747 Points

I'm not sure if I got it so it should be something like this: <ul> <li> <input type="checkbox" name="list" id="item1"> <label for="item1">Item1</label></li> </ul>

Stefan Cutajar
Stefan Cutajar
7,747 Points

Thanks @steven Parker good advice as always :)