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 HTML Basics Getting Started with HTML Lists and Links Challenge

Why does the <a> need to be inside the <Li> when making a list of links? ex. <li><a href="#">some link</a></li>

The code works just as well for me when the <a> is inside or outside the <li> but the code assignment will only except the <a> inside the <li> as a valid answer.

index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Lists and Links</title>
  </head>
  <body>

  Cakes
  Pies
  Candy

  </body>
</html>

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

This is something I've often wondered myself. I'd prefer it if you could wrap the tags your way. But I suppose anchor elements inside list items is more semantic. It has more meaning and is more logical.

I've done some digging online and found a StackOverflow article that explains things further. The key takeaway being that the direct child of an unordered list or an ordered list should be a list item element.

https://stackoverflow.com/questions/12086453/wrap-anchor-tag-around-li-element