6

I am writing an HTML page and noticed that the HTML header tags are not exactly consistent. Some of them require closing tags and some do not.

For example, script tag does require a closing tag but meta does not. Now I wonder why?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Michael
  • 10,185
  • 12
  • 59
  • 110
  • http://stackoverflow.com/a/206409/362536 – Brad Aug 15 '12 at 14:42
  • 1
    See it here: [http://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work][1] [1]: http://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work – Oriol Aug 15 '12 at 14:42
  • 2
    The above links all refer to self closing tag syntax (an XML concept), rather then addressing why script is not defined as EMPTY (and thus requires explicit closing). – Quentin Aug 15 '12 at 14:45
  • Possible duplicate of [Why don't self-closing script tags work?](https://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work) – kenorb Aug 15 '17 at 15:24

2 Answers2

10

The script tag is not an empty (non-closed) tag because it sometimes contains content (Javascript code), but the meta tag never does.
There are two ways to put Javascript in a webpage. The first way is including an external file:

<script src="path/to/my/script.js"></script>

The second way is to put the Javascript right inside the HTML file, like this:

<script>
  Javascript goes here
</script>

So sometimes, the script needs to have content. But the meta tag, on the other hand, only needs to provide a small amount of information about the current page, so an empty tag suffices.

Abraham
  • 20,316
  • 7
  • 33
  • 39
  • 1
    About to post the same answer. Technically some browsers will still work with self-closing script tags, but it is bad practise to use them. – KingCronus Aug 15 '12 at 14:43
2

I believe it is just an arbitrary reason having to do with the system which the current system was built on...

"In case anyone's curious, the ultimate reason is that HTML was originally a dialect of SGML, which is XML's weird older brother. In SGML-land, tags can be specified in the DTD as either self-closing (e.g. BR, HR, INPUT), implicitly closeable (e.g. P, LI, TD), or explicitly closeable (e.g. TABLE, DIV, SCRIPT). XML of course has no concept of this."

from: https://stackoverflow.com/a/3327807/773263

Community
  • 1
  • 1
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225