![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2007
Posts: 3
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Jun 2007
Posts: 93
Rep Power: 2
![]() |
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. |
|
|
|
|
|
#3 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 747
Rep Power: 3
![]() |
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> |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
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.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 150
Rep Power: 1
![]() |
Yeah, wow, I am astonished at that. XHTML is a bit more stricked though.
|
|
|
|
|
|
#7 | |||
|
Programmer
Join Date: Oct 2007
Posts: 39
Rep Power: 0
![]() |
Re: Optional Closing Tags in HTML
Quote:
Quote:
Quote:
![]() |
|||
|
|
|
|
|
#8 | |
|
Man Bear Pig Hunter
Join Date: Jul 2005
Location: NorCal, USA
Posts: 290
Rep Power: 4
![]() |
Re: Optional Closing Tags in HTML
Quote:
I could be wrong. Interesting thread thou. |
|
|
|
|
|
|
#9 | |
|
Newbie
Join Date: Sep 2007
Posts: 5
Rep Power: 0
![]() |
Re: Optional Closing Tags in HTML
Quote:
__________________
http://www.explainth.at |
|
|
|
|
|
|
#10 |
|
Hobbyist Programmer
![]() Join Date: Oct 2007
Location: New York
Posts: 162
Rep Power: 10
![]() |
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> |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |