What are the allowed ways to close self-closing tags for void elements such as in HTML5?

From the W3C specification for HTML:

  • The following is a complete list of the void elements in HTML:

    • area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr
  • Void elements only have a start tag; end tags must not be specified for void elements.

  • Start tags consist of the following parts, in exactly the following order:

    • A < character.
    • The element’s tag name.
    • Optionally, one or more attributes, each of which must be preceded by one or more space characters.
    • Optionally, one or more space characters.
    • Optionally, a / character, which may be present only if the element is a void element.
    • A > character.

From this it seems that we can use either <br> or <br/>. However, the end tag </br> is not valid, so don’t use <br> </br>.

Running the following through the HTML Validation Service indicates as much.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Testing void elements</title>
</head>
<body>
    some lines of txt <br>
    and then some more <br />
    I'm not done yet... <br> </br> <!-- This line generates an error -->
</body>
</html>

So use either <br> or <br/>, just make sure you use them consistently.

Edit: As noted by Brad, <br /> is also valid XHTML, so perhaps it is best to choose this form.

Leave a Comment