Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "script" require closing tag but "meta" does not?

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?

like image 838
Michael Avatar asked Aug 15 '12 14:08

Michael


2 Answers

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.

like image 98
Abraham Avatar answered Sep 20 '22 01:09

Abraham


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

like image 35
Philip Kirkbride Avatar answered Sep 20 '22 01:09

Philip Kirkbride