logoalt Hacker News

gregoriolyesterday at 10:15 AM3 repliesview on HN

I get why you may not close <img> or <br> since they don't contain anything inside, but <p> and <li> should be closed to indicate the end of the content, otherwise it's shows you are mentally lazy and relying on some magic to do the work and guess what you wanted


Replies

QuantumNomad_yesterday at 10:23 AM

To each their own. In simple lists for navigation menus I always omit closing li. There is no ambiguity on what I am intending even with those closing li omitted in such simple cases:

  <nav id=main-nav>
  <ul>
  <li><a href="/">Home</a>
  <li><a href="/hamburgers/">Hamburgers</a>
  <li><a href="/sausages/">Sausages</a>
  </ul>
  </nav>
jeroenhdyesterday at 4:31 PM

<p> indicates a new paragraph. <li> indicates a new list item. Unless otherwise specified, the existing paragraph/list item continues. There's nothing magic about any of this, it's part of the HTML spec.

Laziness doesn't play a role. This isn't XML where you need to repeat yourself over and over again or abusing a bug in the rendering logic; it's following the definitions markdown language you're writing content in.

If you're not too familiar with the HTML language then it's always a safe bet to close your tags, of course.

danarisyesterday at 10:27 AM

The personal judgement isn't really helpful here?

If you don't close your <p> and <li> tags, you risk accidentally having content in the wrong place.

It's something to avoid because it can have bad consequences, not because it (somehow?) makes you a bad person.