Tech News
← Back to articles

You are not required to close your <p>, <li>, <img>, or <br> tags in HTML

read original related products more articles

You are not required to close your

,

  • , , or
    tags in HTML

    Are you an author writing HTML?

    Just so we’re clear: Not XHTML. HTML. Without the X.

    If you are, repeat after me, because apparently this bears repeating (after the title):

    You are not required to close your

    ,

  • , , or
    tags in HTML.

    (The same applies to over a dozen other elements but these are the most common ones.)

    There are a number of reasons it is good practice to do so (which I’ll get to later in this article), but it is not wrong or inherently bad practice not to do so with elements with optional end tags or elements without end tags (believe it or not, these exist — they’re called void elements). Browsers do not treat missing optional end tags as errors that need to be recovered from.

    Anyone telling you otherwise about these elements was unfortunately misinformed by the one before them. Please correct them, perhaps by pointing them to this article; chances are you were referred here by me or someone else for this very reason.

    For the sake of convenience, “HTML5” refers to either WHATWG HTML (the living standard) or W3C HTML5, whichever you’re personally more comfortable with. None of the differences between the two are pertinent to this article, so I won’t even make any references to either specification. But I consider the living spec by WHATWG canon, so all spec links will point to that.

    Table of contents

    ... continue reading