PDA

View Full Version : Optional Closing Tags in HTML



Carrym
Mar 21st, 2007, 05:41 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?

Nightfire
Mar 21st, 2007, 05:43 PM
Never heard of that one before. Where did you read that from?

Silo
Mar 21st, 2007, 05:57 PM
Craziness. I never knew that either. Depending on your doctype though browsers are pretty forgiving of missing elements - for example you've been able to leave out the closing </li> on a line item for a long time because the closing of it is implied in when the next <li> or closing </ul> begins.

In XHTML however, nothing is implied. :) (Edit: well, unless you don't declare a restrictive doctype or you don't care about validating against that doctype)

- Silo

gsnedders
Mar 21st, 2007, 07:39 PM
The <html>, <head> and <body> tags (both opening and closing) are all required but may be omitted. I've never had any issues without them.

felgall
Mar 21st, 2007, 08:52 PM
If you want to have maintainable web pages and are following decent web standards then your standards will specify that all of those tags which web browsers are required to treat as optional will be listed as mandatory in your standards. They are only optional so that web browsers can still display badly written unmaintainable web pages as well as properly written ones.

croatiankid
Mar 21st, 2007, 09:15 PM
You've got a relatively short "discussion" on this here (http://codingforums.com/showthread.php?t=18346&page=4), starting at about post #58.

Arbitrator
Mar 21st, 2007, 11:14 PM
The list of elements that you can omit (http://www.w3.org/TR/html401/index/elements.html) is found in the specification itself. The second and third columns of the list are the relevant part. For those four elements that are listed as having optional start tags, they will be inserted into an HTML document whether you explicitly declare them or not. You can also omit the start tags while providing the end tags for those elements. I haven’t really used the syntax, but I’m pretty sure that it works fine in current browsers.

As for whether it’s a good idea to do this, I would say “no”. It is technically valid HTML, however.

rmedek
Mar 22nd, 2007, 01:41 AM
You've got a relatively short "discussion" on this here (http://codingforums.com/showthread.php?t=18346&page=4), starting at about post #58.

Good eye… Just so everyone's clear, the original poster is (was) a signature spammer. But since the posts are sparking some good discussion, the signatures have been removed and the posts aren't being deleted. Go figure, spammers doing some good for once. :D

croatiankid
Mar 22nd, 2007, 09:17 AM
the original poster is (was) a signature spammer. But since the posts are sparking some good discussion, the signatures have been removed and the posts aren't being deleted. Go figure, spammers doing some good for once. :D
wow never knew lol