Are XHTML style close tags valid in HTML? What I mean is, in XHTML we use <link href="style.css" type="text/css" rel="stylesheet" />
. Is this valid in HTML? or should I be using <link href="style.css" type="text/css" rel="stylesheet"></link>
?
views:
79answers:
3You should use <link>
in HTML. <link/>
in XHTML. If you are feeding XHTML as text/html then it really doesn't matter, because technically it's invalid HTML, unreal XHTML, HTML pretending to be XHTML but the Content-Type is text/html
so not a fully fledged XHTML document.
If you feed xhtml style to HTML, it won't be valid but the browser will parse it properly.
You should remember which elements are self closing, script
is not self closing and link
is self closing. There's a list out there in the w3 spec somewhere.
They are invalid in HTML4 for the LINK
element.
Start tag: required, End tag: forbidden
But XML-style tags as in your question are valid in HTML5:
Authors may optionally choose to use this same syntax for void elements in the HTML syntax as well.
Basically, HTML5 allows XML/XHTML style markup. That's the nice thing of HTML5. You aren't forced to serve XHTML as application/xml+html
which would only cause IE to havoc. Just serve it as text/html
with a <!DOCTYPE html>
in top of the page and you're safe.
To quote the W3 validator regarding self-closing tags:
The sequence can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates the tag '). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.