Optional closing elements

Last updated October 1, 2021 by Jacob Paris

Several HTML elements do not require closing tags

  • <html>
  • <head>
  • <body>
  • <p>
  • <dt>
  • <dd>
  • <li>
  • <option>
  • <th>
  • <tbody>
  • <tr>
  • <td>
  • <tfoot>
  • <colgroup>

That means that this is valid html

<html>
<head> <title> My blog </title>
<body>
<h1> My blog </h1>
<p> Welcome to my blog
<p> Here are a list of my posts
<ul>
<li> My first post
<li> My second post
<li> My third post
</ul>

As a general rule I don't recommend writing html like this, as it can be hard to tell when an element is meant to end or meant to nest, especially when the formatting isn't as clean as possible.

There's a dozen or so HTML tags which optional closing tags, so this is legitimate valid HTML markup