-3

According to the W3C, "Void elements can't have any contents (since there's no end tag, no content can be put between the start tag and the end tag)".

However, it seems to me that the end-tag is not required for an html element has a content (eg: td or th or tr TAG: for these, the end-tag is optional and -in any case- implicit, but does not make them "void"). In short, HTML "void" elements are (really) "empty" elements? Given that the true and only difference that distinguishes them from html elements "normal" is that they have no closing tag, it would be better to call mono-tag?

I apologize if this place was not the right one to ask questions like that.

Thanks for your time.

<table>
  <tr>
    <th>1
    <th>2
  </tr>
  <tr>
    <td>3
    <td>4
  </tr>
</table>
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Juri
  • 311
  • 4
  • 12
  • From what do you determine that these end tags are optional? – Scott Hunter Jan 03 '17 at 15:50
  • 1
    You'll see in your browser's developer tools that those elements are closed automatically (that is, you'll find ``). These are not, however, void elements. Read more: http://blog.teamtreehouse.com/to-close-or-not-to-close-tags-in-html5 – Jon Uleis Jan 03 '17 at 15:51
  • 1
    `td`: https://www.w3.org/TR/2014/WD-html51-20140617/tabular-data.html#the-td-element `th`: https://www.w3.org/TR/2014/WD-html51-20140617/tabular-data.html#the-th-element `tr`: https://www.w3.org/TR/2014/WD-html51-20140617/tabular-data.html#the-tr-element – Juri Jan 03 '17 at 15:51
  • 3
    `"it would be better to call mono-tag?"` - So your only question is whether or not the W3C documentation should use a different name? What exactly are you asking? – David Jan 03 '17 at 15:52
  • 1
    @David, I do not judge the W3C recommendations. Wondering why the "void elements" are called "empty" to distinguish them from "normal elements," when it seems to me that even certain "normal elements" are just as necessarily empty: **is the tag `script` with attribute `src` a void element?** – Juri Jan 03 '17 at 17:29
  • @Juri: No, `script` is not a void element. Because it *can* have content. And in fact *must* have a closing tag in all cases. For that specific element there are rules for when content should or should not be present, but this is very different from a void element which has no content or closing tag. – David Jan 03 '17 at 17:32
  • @David, tag script with atrribute src shows us that the (real) difference between void and normal elements is the end tag, not the (empty) content. – Juri Jan 03 '17 at 17:36

1 Answers1

7

In short, HTML "void" elements are (really) "empty" elements?

To be more precise, a void element is an element that cannot have content. That is, a void element is an element that is only and always empty. Furthermore, a void element cannot have an end tag — the end tag isn't optional, it's forbidden. Which means <br></br> and <img src="example.png"></img> are both invalid HTML.

Elements with optional end tags such as tr, th and td can have content and are therefore not void elements. They can, however, be empty, such as the th and td elements here:

<table>
  <tr><th><th></tr>
  <tr><td><td></tr>
</table>

See also: Are void elements and empty elements the same?

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Thank you, that post asking my own question (change only upvotes/downvotes). – Juri Jan 03 '17 at 15:59
  • I meant that the essential feature of "void elements" is not to be empty (even the html tag `script` with attribute `src` **must** be empty or void) but only that of not necessarily having the end tag ( this is the real essential feature of the "void elements"). So I was wondering if it was correct to call them "empty" to distinguish them from normal elements... – Juri Jan 03 '17 at 17:17