mdo/code-guide

Why necessarily specifying optional closing tags?

matthewslouismarie opened this issue · 0 comments

Hi,

The Code Guide reads:

Don’t omit optional closing tags (e.g. or ).

I think it would be good to either give a very good reason or otherwise remove this statement. The HTML 5.1 (and probably the previous ones) explicitly say the closing tags are not necessary in certain precise circumstances, and even give examples of HTML code where the implicit closings tags are not written. I am not aware of them recommending against this practice, it rather looks like they are encouraging it since they do omit them in some code examples (although some other code snippets of the specification do not omit optional closing tags).
Besides, this makes the code lighter and much easier to read. Just compare the two:

…
<tr>
  <th>Price in 2017
  <td>78,50
  <td>79,50
  <td>82,50
  <td>86,00
  <td>107,50
  <td>87,00
  <td>100,00
  <td>90,50
  <td>90,50
  <td>82,00
  <td>88,00
  <td>99,00
<tr>
…

With the closing tags:

…
<tr>
  <th>
    Price in 2017
  </th>
  <td>
    78,50
  </td>
  <td>
    79,50
  </td>
  <td>
    82,50
  </td>
  <td>
    86,00
  </td>
  <td>
    107,50
  </td>
  <td>
    87,00
  </td>
  <td>
    100,00
  </td>
  <td>
    90,50
  </td>
  <td>
    90,50
  </td>
  <td>
    82,00
  </td>
  <td>
    88,00
  </td>
  <td>
    99,00
  </td>
</tr>
<tr>
…

Now I know that I am not obliged to put the content of the td elements on a new line, but if I had HTML elements nested inside td elements (which I do on several of my projects), I would have to anyway.
When working on complex HTML structures such as this one (I am working on documents with several HTML tables spanning about 300 lines each without the use of ending tags), not omitting them would be both inefficient and unreadable, while not using them would be completely valid.