Reputation: 379
Does anyone know of a good reference or rule of thumb for when to finish a tag properly <script></script>
or when to use the simpler <script />
.
Perhaps a couple of examples of which is best for, eg. <input></input>
vs <input />
, <script />
vs <script></script>
etc etc.
Upvotes: 1
Views: 199
Reputation: 943214
Never use <element />
in HTML since, depending on the version of HTML you are using and where you put it it either:
The list of elements in HTML 4.01 has a column which shows you when start and end tags are optional or forbidden.
If you are writing XHTML then use <element />
when, and only when, the end tag is Forbidden in HTML 4. This is part of the HTML compatibility guidelines. (If you are one of the very tiny number of people serving XHTML as application/xhtml+xml (thus excluding users of IE 8 and lower) then you can use the syntax on any element).
If you are writing HTML 5. Then you can use that syntax under the same rules as XHTML - but it is optional and therefore I wouldn't bother.
Upvotes: 3
Reputation: 9126
It really depends on your document definition type. If you are unsure which one best fits your doc type then you could always just run it through a validator which will complain if it sees anything that doesn't fit your doc type. For example:
Upvotes: 0
Reputation: 8562
Usually it's your preference, although it also depends on what type of html you're going for. 4 vs. 5, strict, loose or transitional.
Although I would recommend against doing <script />
. It seems that if you do the short version, IE doesn't actually download your JS file! <script></script>
works though.
Upvotes: 0