Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   HTML / XHTML / CSS (http://www.programmingforums.org/forum27.html)
-   -   Optional Closing Tags in HTML (http://www.programmingforums.org/showthread.php?t=14055)

WIND Sep 28th, 2007 10:16 AM

Optional Closing Tags in HTML
 
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?
_________________
Parental control software free parental control software

MiKuS Oct 1st, 2007 1:03 AM

I didn't know this either.

I'm going to say if it works don't change it. I close all my tags because if they didn't need to be closed, there would be no closing tags, or the tag would be self closing
(<br />, <hr />. Although it's good practice to write these tags as <hr /> you can write them like <br> and <hr>)
I guess do whatever works.

Jimbo Oct 1st, 2007 3:35 AM

That's because HTML is whacky. And because of it, the parsers have to be pretty ingenious to allow for badly formed markup like that, which is partly why IE 4-6 have some really weird behaviors. Note that XHTML, which is what everybody should be using these days, doesn't allow omission of closing tags; it even requires closing tags that don't come in pairs, like <img>, <br>, and <hr>

DaWei Oct 1st, 2007 3:42 AM

The problem with XHTML is IE (non)support. That's a lot of clients. Personally, I've almost completely reverted to HTML 4.01 strict.

Komodo Oct 1st, 2007 4:52 AM

Substandard code is leading to degradation of the internet, some sites are already gettting quite bad. Take a look at Myspace.com for instance. Some of the worst HTML code ever. So bad, in fact, that my browser is no match for it's mighty crap-code, and it just freezes upon viewing.

Grich Oct 6th, 2007 8:58 AM

Yeah, wow, I am astonished at that. XHTML is a bit more stricked though.

WaltP Oct 18th, 2007 5:22 AM

Re: Optional Closing Tags in HTML
 
Quote:

Originally Posted by WIND (Post 134406)
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?

Technically, they are not really optional. It's just that most browsers are badly written and don't really care. I for one consider this a problem -- but it's SOP for M$. They write crap, and let those that purchase the software beta-test it. Then charge the beta-testers when they need help getting around the bugs.

Quote:

Originally Posted by DaWei (Post 134510)
The problem with XHTML is IE (non)support. That's a lot of clients. Personally, I've almost completely reverted to HTML 4.01 strict.

This is not a problem with XHTML. It's a problem with IE.


Quote:

Originally Posted by Grich (Post 134829)
Yeah, wow, I am astonished at that. XHTML is a bit more stricked though.

stricked? Do you maybe mean strict? :-/

Ghost Oct 18th, 2007 7:42 AM

Re: Optional Closing Tags in HTML
 
Quote:

Originally Posted by DaWei (Post 134510)
The problem with XHTML is IE (non)support. That's a lot of clients. Personally, I've almost completely reverted to HTML 4.01 strict.

WaltP, what he was saying there if I understand correctly, is that the issue IS with IE's support of the XHTML joking that it does not. Therefore: (non)support

I could be wrong. Interesting thread thou.

ExplainThat Oct 18th, 2007 10:07 AM

Re: Optional Closing Tags in HTML
 
Quote:

Originally Posted by WIND (Post 134406)
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?
_________________
Parental control software free parental control software

I tend not to leave out closing tags even when I know that it works. However, on the rare occassion that I have to I check to see what Google is doing - just take a look at their SERPs. There are tons of missing closing tags - for instance, they hardly ever close a listitem. The way I figure, if Google is skipping a closing tag then it should generally be safe with most browsers since I cannot imagine that they would leave any browser that could possibly matter out in the cold.

cscgal Oct 18th, 2007 11:15 AM

Re: Optional Closing Tags in HTML
 
As far as I am concerned, every single tag that's opened must be closed. If there is no reason for a tag to be closed (such as an image tag or line break) then it should be self closing by ending with a slash as in <tag ... />. Just because it doesn't error out doesn't mean it's okay to do. I feel a C++ void main() lecture coming on ...

---

What often happens is web browsers will implicitely add a closing tag when it is impossible for it to remain open. It's impossible to remain in the <head> section once the <body> has started, so let's implicitely close the head tag before the body. This same thing happens with lists. A lot of people type <li> at the start of a list element without closing it as so:
:

<ul>
  <li>One.
  <li>Two.
</ul>

This is wrong, but it's impossible for something to be a part of two list elements of the exact same list, so a web browser will implicitely close the first list element before moving on to the second one. If you get into this habit, you'll inevitably not close something that technically could remain open (and therefore the browser won't be nice enough to close it for you), even though it's incorrectly nested or not what you intended.


All times are GMT -5. The time now is 3:07 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC