Do you REALLY have to close list tags?

I’m always on the lookout for shortcuts. Thus, If I have a long list, I’ll skip the closing </li> tag until I get to my last list item.

But is that really OK?

I was taken aback by the heat this issue generates online, although I guess I should expect heat just about anywhere online in today’s Web culture. A sampling response to a post on social media that a student’s professor (coulda been me) said closing </li> tags are optional:

  • Your professor should be fired. <li> is not a self-closing tag and needs a separate closing
  • it’s optional in most cases. The professor is correct.
  • Optional or not, a closing </li> tag should never be considered ‘optional’ if you wish to write proper HTML code.
  • That’s your mere opinion. “Proper” HTML is determined by specification, not by your opinion.

The definitive answer is:

Browsers will have no difficulty figuring out that when a new open <li> tag appears, of if a close </ol> or </ul> tag appears, the list item is over. Is anyone having trouble seeing the four unordered bullet points in the list above? If so, post a comment (and a screencap, with your browser info). But I’m willing to bet (that’s just an expression) everyone is seeing that list even though I didn’t close the list elements with </li> tags.

Does that mean there’s no reason to close list tags? No. There is a reason: code editors, programmed with “validation” rules that go back to the 10 Commandments or earlier, sometimes will give you a lot of grief if you don’t close the tags. And, if you’re in a class and your professor says close ’em, well, do what he/she says for now.

Now you know the facts, make your own call 🙂

Print Friendly, PDF & Email