1

I always want to ask this question:

Is this validate

<a><li></li></a>

Or should always have

<li><a></a></li>

Is the first way wrong or you are allow to do that?

Bill
  • 17,872
  • 19
  • 83
  • 131

3 Answers3

7

the first one is wrong, as only <li> is to be a child of a list. the second is correct.

by what i understand, you want the whole list item to be "clickable". putting everything in <a> is also viable - block AND inline elements. this is perfectly valid in HTML5. won't validate in older HTML though. however, it does act correctly, given that <a> is given the style of display:block

A clickable <li> using an <a> tag - no JS to be used. Is it legal HTML?

Community
  • 1
  • 1
Joseph
  • 117,725
  • 30
  • 181
  • 234
2

The first choice is incorrect. Second choice is correct.

RePRO
  • 265
  • 6
  • 18
1

According to w3.org, only li tags are allowed in a ul or ol:

http://www.w3.org/TR/html401/struct/lists.html#h-10.2

Shane Andrade
  • 2,655
  • 17
  • 20