DEV Community

Discussion on: Why hasn't the 'script' tag gotten a void version, yet? (E.g. 'extscript')

Collapse
 
nicozerpa profile image
Nico Zerpa (he/him) • Edited

Ironically, the problem is not exactly the lack of standardisation, but too much of it!

In regular HTML, there are two kind of elements: void and non-void. A void element does not require a closing tag: <hr>, <img>, <meta>, and others. Non-void elements do need a closing tag, but you can put content inside them: <title>, <div>, <a>.

But... in the early 2000s, the W3C (one of the organisations that define web standards), created another HTML standard. known as XHTML. It was basically HTML with XML syntax.

XML does not support void elements, every single tag needs to be closed, but they do have self-closing tags. In XML, you create a self-closing tag by putting a / at the end of the tag: <br/>, <img/>, etc.

XHTML fell out of favour long ago and self-closing tags don't exist in regular HTML and. Actually, Firefox is technically correct by not supporting them (And it seems Chrome doesn't either.)

If some browsers still support self-closing tags in regular HTML, that's just because there were lots of web devs using them, so the browser's dev team decided to support them anyway. But don't be surprised if they decide to drop support in the future.

The <script> element is not void because you can write content on it, e.g: an inline script. Also, HTML doesn't have tags that sometimes are void and sometimes not. A void element is always void. Therefore, when an element sometimes require content should be a non-void element.

The only alternative should be to create a new tag for loading external scripts, but I don't expect that to happen soon.