View Full Version : Optional Closing Tags in HTML
DESIGN
08-15-2007, 12:27 PM
For as long as I've been validating web pages, I never realized that the closing </head> tag was optional in HTML. I feel as if I've missed the boat at times.
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?
jscheuer1
08-15-2007, 02:42 PM
Amazing! I didn't know either. It would never hurt to keep it in though. There couldn't be any question really, in an otherwise valid document, where the head ends.
I only just tested this in the w3c validator. Without seeing it in the standards, I'm not certain whether it is a glitch in the validator or an actual part of the standards. I did find an archived (1995) reference to its being optional, but would rather see it specifically for a given DOCTYPE to be certain. Browsers will error correct that sort of thing.
According to the archived reference, there is a lot that is optional. And, this in fact passes strict validation:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<div>Hi</div>
It is valid. I don't know how browsers might parse it, though; it could be that they'd resort to error-correction (after all, NET is valid in HTML too, but browsers just error-correct it out). It would also lower potential forwards-compatibility with XHTML, in which these tags are not optional. This is also valid Strict:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<title//<p>
This thread was actually spam, but since it contained an interesting point I'll just remove the signature.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.