Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 28th, 2007, 9:16 AM   #1
WIND
Newbie
 
Join Date: Sep 2007
Posts: 3
Rep Power: 0 WIND is on a distinguished road
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
WIND is offline   Reply With Quote
Old Oct 1st, 2007, 12:03 AM   #2
MiKuS
Hobbyist Programmer
 
Join Date: Jun 2007
Posts: 134
Rep Power: 2 MiKuS is on a distinguished road
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.
MiKuS is offline   Reply With Quote
Old Oct 1st, 2007, 2:35 AM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
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>
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Old Oct 1st, 2007, 2:42 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 1st, 2007, 3:52 AM   #5
Komodo
Hobbyist Programmer
 
Komodo's Avatar
 
Join Date: May 2005
Location: Scranton, PA
Posts: 112
Rep Power: 0 Komodo is an unknown quantity at this point
Send a message via AIM to Komodo Send a message via MSN to Komodo
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.
Komodo is offline   Reply With Quote
Old Oct 6th, 2007, 7:58 AM   #6
Grich
Hobbyist Programmer
 
Grich's Avatar
 
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 198
Rep Power: 2 Grich is on a distinguished road
Yeah, wow, I am astonished at that. XHTML is a bit more stricked though.
Grich is offline   Reply With Quote
Old Oct 18th, 2007, 4:22 AM   #7
WaltP
Programmer
 
Join Date: Oct 2007
Posts: 39
Rep Power: 0 WaltP is on a distinguished road
Re: Optional Closing Tags in HTML

Quote:
Originally Posted by WIND View Post
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 View Post
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 View Post
Yeah, wow, I am astonished at that. XHTML is a bit more stricked though.
stricked? Do you maybe mean strict?
WaltP is offline   Reply With Quote
Old Oct 18th, 2007, 6:42 AM   #8
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 295
Rep Power: 4 Ghost is on a distinguished road
Re: Optional Closing Tags in HTML

Quote:
Originally Posted by DaWei View Post
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.
Ghost is offline   Reply With Quote
Old Oct 18th, 2007, 9:07 AM   #9
ExplainThat
Newbie
 
Join Date: Sep 2007
Posts: 5
Rep Power: 0 ExplainThat is on a distinguished road
Re: Optional Closing Tags in HTML

Quote:
Originally Posted by WIND View Post
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.
__________________
http://www.explainth.at
ExplainThat is offline   Reply With Quote
Old Oct 18th, 2007, 10:15 AM   #10
cscgal
Hobbyist Programmer
 
cscgal's Avatar
 
Join Date: Oct 2007
Location: New York
Posts: 163
Rep Power: 10 cscgal is on a distinguished road
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.
cscgal is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
start Learning HTMl smita HTML / XHTML / CSS 0 Mar 15th, 2007 7:38 AM
converting string to float beginnerCCC C 22 Oct 2nd, 2006 11:59 PM
Basics of HTML Tutorial crawforddavid2006 HTML / XHTML / CSS 14 Jul 11th, 2006 7:40 AM
Basic HTML Tutorial - Reuben Keeney ReubenK HTML / XHTML / CSS 14 Mar 26th, 2006 5:50 AM
HTML =/= Programming Sane Coder's Corner Lounge 32 Mar 8th, 2006 2:50 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:26 AM.

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