Forum Moderators: open
While I'm all for trimming excess code, I just cannot for the life of me strip out closing tags because they are optional in HTML. I'd be concerned that something, somewhere would not parse the document correctly if I removed the closing </head> element.
Are my concerns unfounded?
The start and end tags for HTML, HEAD and BODY are all optional [w3.org] in HTML4.01. It's perfectly valid to leave them all out.
I'd be concerned that something, somewhere would not parse the document correctly if I removed the closing </head> element.
I wouldn't omit them either. Just because a page validates does not guarantee it will work in all browsers. (Pigeons <- Cat -> Pigeons) :)
Google "Anne's Weblog" for an example of minimalist, valid HTML4.01 strict pages in action.
I'm not sure if the specification should be interpreted in this way. The DTD specifies, as an example that the TITLE tag requires a start and a close tag, whereas the P tag requires a start tag and the close is optional. In the case of HEAD the DTD contains:
<!ELEMENT HEAD O O (%head.content;) +(%head.misc;) -- document head -->Which makes the start tag optional as well, therefor I would assume it is implied that the HEAD block is not required as a whole, but, if it is started it must be finished.
end tag for "HEAD" which is not finished.
"BODY" not finished but document ended.
Andrew
Similarly, say directly after the DOCTYPE the browser finds a <title> start tag. The browser knows that a title element can never exist outside of a head element so it knows that it can generate a head parent to go around it.
Now combine the two above scenarios together. From a total absence of start and end <head> tags we can still infer the presence of a head element. This is why it's legitimate HTML.
Of course this only applies to HTML, not XHTML.
On the other hand at work we send a lot of database reports to the browser and the html we create there normally has no head or body tag, just a table with the results of the query. Works just fine and a lot easier to code as it is independent of the target application. Users can open the html files in spreadsheets or word processors if they need to.