3

I've been looking through a ton of sites recently to get a better understanding of how large websites structure their HTML5 pages.

I noticed that they tend to do

<script src="test.js"></script> 

Instead of

<script src="test.js" />

But do

<link rel="stylesheet" href="test.css"/> 

Instead of

<link rel="stylesheet" href="test.css"></link>

Even in this technique blog they do so, why is this a preferred design style?

http://net.tutsplus.com/tutorials/html-css-techniques/25-html5-features-tips-and-techniques-you-must-know/

2

3 Answers 3

3

That's because the web is normalized and some things are possible according to the norm and some other aren't. With a logic behind being that some elements are naturally void and some others aren't.

From the w3.org on the script element :

A script element must have both a start tag and an end tag.

So you can't have

<script src="test.js" />

On the link element :

The link element is a void element. A link element must have a start tag but must not have an end tag.

A link element, which can't have a content, can be written

<link rel="stylesheet" href="test.css"/>

or even (much better if you don't try to write XHTML)

<link rel="stylesheet" href="test.css">
2
  • It's also the rule... not just the norm.
    – BoltClock
    Jan 31, 2013 at 7:34
  • @BoltClock It might due to my poor mastering of the English language (or the fact I'm still drinking my first coffee) but I fail to see this distinction. What do you mean ? Jan 31, 2013 at 7:39
1

According to the HTML standard, the ending tag is required for the script tag, it can't be a self-closing tag.

Self-closing tags are used in XHTML for tags that doesn't require a closing tag in HTML, like the link and input tags.

0
1

In HTML, there are tags which are always self-closed. For example,

<hr>Some content here</hr>

does not make any sense. In the same way, there are tags which cannot be self-closed. tag is one of them.

I am not sure about the reason of no self-closed tags, but the reason might come from the fact that the tag was intended to always contain code inside.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.