SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <tr> and <td> closing tags supposed to be optional, but can cause error? in XHTML?

    sometimes I don't add </tr> or </td> in table formatting, and most of the time it is no problem. (HTML 4.01 spec says both of them are optional).

    But I remember in some situation, they gave some problem with the table formatting until i added the </td> and </tr> back and the problem went away.

    could it be that because the page was in XHTML 1.0 instead and that mandates a closing tag? although, modern browsers should be smart enough to understand <td>1<td>2 and not mess up even when it is XHTML 1.0. Does someone know, if an actually browser will choke if </td> or </tr> is not used? thanks.

  2. #2
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,745
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by winterheat View Post
    sometimes I don't add </tr> or </td> in table formatting, and most of the time it is no problem. (HTML 4.01 spec says both of them are optional).

    But I remember in some situation, they gave some problem with the table formatting until i added the </td> and </tr> back and the problem went away.

    could it be that because the page was in XHTML 1.0 instead and that mandates a closing tag? although, modern browsers should be smart enough to understand <td>1<td>2 and not mess up even when it is XHTML 1.0. Does someone know, if an actually browser will choke if </td> or </tr> is not used? thanks.
    In XHTML it is required to end all tags where it is due. For more information read the stickied thread about XHTML. FF may be smart enough to know when to not choke, but what about IE? How would you fix that? Also your way wouldn't validate and it is poor coding practice to not end all tags properly
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    In XHTML no closing tag is optional!
    That also means <br> becomes <br/>, <hr> becomes <hr/> etc
    Just like XML, all tags have to be closed
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,745
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    A good way to fix errors is by using W3's validation services. It is a great trip there because you get another site dissing your own . Oh and you can fix markup .

    Off Topic:

    Is that better way to tell them?

    Post 600! I'm a guru now . Paul move over.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  5. #5
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BoltZ View Post
    In XHTML it isn't required to end all tags where it is due. For more information read the stickied thread about XHTML. FF may be smart enough to know when to not choke, but what about IE? How would you fix that? Also your way wouldn't validate and it is poor coding practice to not end all tags properly
    you mean it "is" required? my main concern is, where can it *actually* mess up a modern browser? i remember seeing it happen before, but usually i work with HTML but not XHTML.

  6. #6
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,745
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I had it as "is" but my post got edited by a certain someone (BBoardx..)

    Quote Originally Posted by FAQ ON THIS
    XHTML, being XML, must be well-formed. Every element must have an end tag, or use the self-closing tag syntax. HTML allows some end tags and even some start tags to be omitted.
    .

    Yes it can mess up a browser. It is required to conform to the rules.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Any missing close tags in XHTML will stop most browsers from being able to display the page at all. The only browser that doesn't care about whether you close your tags in XHTML or not is Internet Explorer because it only offers the file for download as it cannot display XHTML at all.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,745
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I am reading the FAQ's on HTML since I have W3schools certification tomorrow (hope I pass).

    IE just plain doesn't support XHTML. They won't display it: they have no idea what the f*ck it is.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  9. #9
    SitePoint Evangelist Karpie's Avatar
    Join Date
    Jul 2007
    Location
    Perth, Australia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BoltZ View Post
    I am reading the FAQ's on HTML since I have W3schools certification tomorrow (hope I pass).
    OK I had to go look it up now, I'd never heard of such a certification... that's some sort of really bad joke, right? :/

  10. #10
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Karpie View Post
    OK I had to go look it up now, I'd never heard of such a certification... that's some sort of really bad joke, right? :/
    http://www.w3schools.com/cert/cert_html.asp
    http://www.w3schools.com/cert/pic_html_certif.jpg

  11. #11
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's interesting... the exam doesn't say whether it is open book or not (like you can read any book or check on the internet provided that you finish the exam in 70 minutes). why i think it might be more relevant when it is open book? because when we work in real life, we actually can use any reference book or look up any info on the internet.

    by the way, Boltz already became a "Sitepoint Guru" by posting more than 600 posts... hm... it sounds better than Sitepoint Mentor or Sitepoint Advisor, just that there is no badge... only if he can use CSS to overlay a badge under his name using negative margins or position: relative.
    Last edited by winterheat; Oct 28, 2008 at 00:57.

  12. #12
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by winterheat View Post
    could it be that because the page was in XHTML 1.0 instead and that mandates a closing tag?
    If the page displayed at all without those end tags, you weren't using XHTML. My guess is that you were using pretend-XHTML (XHTML markup served as text/html). That is just HTML with syntax errors in it, it's not XHTML.

    Quote Originally Posted by winterheat View Post
    although, modern browsers should be smart enough to understand <td>1<td>2 and not mess up even when it is XHTML 1.0.
    No, they shouldn't. In fact, they mustn't. The XML specification mandates that an XML parser abort as soon as it encounters a well-formedness error. And since XHTML is an application of XML, a compliant parser must stop if a </td>, </th> or </tr> tag is missing.

    Quote Originally Posted by ScallioXTX View Post
    In XHTML no closing tag is optional!
    That also means <br> becomes <br/>, <hr> becomes <hr/> etc
    You can also write <br></br> and <hr></hr>, although that may cause problems if you use pretend-XHTML.

    Quote Originally Posted by ScallioXTX View Post
    Just like XML, all tags have to be closed
    That's because XHTML is an application of XML.
    Birnam wood is come to Dunsinane

  13. #13
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    If the page displayed at all without those end tags, you weren't using XHTML. My guess is that you were using pretend-XHTML (XHTML markup served as text/html). That is just HTML with syntax errors in it, it's not XHTML.


    No, they shouldn't. In fact, they mustn't. The XML specification mandates that an XML parser abort as soon as it encounters a well-formedness error. And since XHTML is an application of XML, a compliant parser must stop if a </td>, </th> or </tr> tag is missing.
    I see. thanks. so if i am for sure using HTML 4.01, then no need to serve the </td> and </tr> closing tags...

    if using XHTML 1.0, then must use </td> and </tr>...

    i think i saw a doc saying when a tag is empty, then no need closing tag, but that means it is one of those <br> or <hr> where you can either close it by </br> or </hr> or you still have to close it by <br /> and <hr /> huh? in other words, you always have to close it, just that for those, you don't have to use a closing tag but use a self-closing one.

    i wonder if i am serving a large table of numeric data, such as ... 1.2MB, and let's say each row has 8 cells, then how much faster it is if the doc has no </td> and </tr> versus if there are, assuming the data is passed using "gzip, deflate" and the transfer rate is 300kb/s. will do some experiment later... right now... working on a project using greasemonkey...

  14. #14
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by winterheat View Post
    I see. thanks. so if i am for sure using HTML 4.01, then no need to serve the </td> and </tr> closing tags...
    Not syntactically, no. But those end tags tend to make the markup much more easy to read for human beings.

    Quote Originally Posted by winterheat View Post
    if using XHTML 1.0, then must use </td> and </tr>...
    Yes, there must be a matching end tag for every start tag in X(HT)ML.

    Quote Originally Posted by winterheat View Post
    i think i saw a doc saying when a tag is empty, then no need closing tag
    The element types declared as EMPTY in the HTML DTDs must not have an end tag. There are no </br>, </hr>, </img>, </meta> tags etc in HTML.

    For element types that can have content, the end tag is required even if the element is empty (except for those element types that have an optional end tag).

    In XHTML it's different, since it must be well-formed. Even empty elements need a closing tag. Instead of <br></br> etc XML offers a shorter notation, <br/>. It's called a null end tag (NET), and it's a feature that is theoretically available even in HTML (albeit with a different syntax), but no browsers support it in HTML.

    Using <br/> in HTML actually means something different than in XHTML (it means <br>&gt;). But all browsers have buggy parsers that interpret it as <br>, which is why pretend-XHTML works.

    In real XHTML you can use NET syntax for any empty element, even if it's not declared as EMPTY. For instance, the following is perfectly valid XHTML:
    Code:
    <script type="application/javascript" src="script.js"/>
    You can't use this in pretend-XHTML, though. NET syntax can only be used with EMPTY elements in pretend-XHTML.

    Quote Originally Posted by winterheat View Post
    but that means it is one of those <br> or <hr> where you can either close it by </br> or </hr> or you still have to close it by <br /> and <hr /> huh?
    In HTML you just use <br> and <hr>. In XHTML you'd normally use <br/> and <hr/>. In real XHTML you could also use <br></br> and <hr></hr>, but there's no reason to. In pretend-XHTML it's customary to leave a space before the NESTC delimiter (<br /> etc) to cater for extra-buggy HTML parsers.
    Birnam wood is come to Dunsinane

  15. #15
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    Here is an example of someone really putting HTML4's "optional" tags to the test. This page is actually valid, though (deliberately) sloppy.

    It would not be as XHTML but he's smart enough to know that XHTML gives no benefits if served the way he's serving it so he stayed with HTML4.

  16. #16
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    Here is an example of someone really putting HTML4's "optional" tags to the test. This page is actually valid, though (deliberately) sloppy.

    It would not be as XHTML but he's smart enough to know that XHTML gives no benefits if served the way he's serving it so he stayed with HTML4.
    no <head>, no <body>, no </li>, yet it is valid 4.01 strict code. He is my new hero. (just kidding).

  17. #17
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't call it sloppy. Impractical and perhaps a bit provocative, yes, but not sloppy.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  18. #18
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    Hmmm, okay, not sloppy, but definitely provocative : ) He told me "don't believe everything they tell you" and maybe wants his site to be as lean as possible.

    I styled the page originally and rewrote the HTML from what is was originally, but he removed my "looks nice at 600x800" setup and then removed all the "superfluous" tags lawlz. So I didn't want my name on the page.

  19. #19
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,072
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BoltZ View Post
    A good way to fix errors is by using W3's validation services. It is a great trip there because you get another site dissing your own . Oh and you can fix markup .

    Off Topic:

    Is that better way to tell them?

    Post 600! I'm a guru now . Paul move over.
    When using FF Ctrl+A will upload the current page to the W3's validation service.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  20. #20
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    When using FF Ctrl+A will upload the current page to the W3's validation service.
    also, if you install Wed Developer's Tool on FF, at the top right corner of the window at the toolbar, you will see the checkmark for HTML and CSS as well.

    PS. I just found that a green checkmark for HTML doesn't mean anything... it merely indicates it is Compliance mode but doesn't validate the HTML. The CSS checkmark does say there is no CSS error... but supposedly the w3c.org one is more authoritative.
    Last edited by winterheat; Oct 28, 2008 at 15:49.

  21. #21
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using Opera 9.5+ Ctrl+Shift+Alt+U will send the current page to W3C's HTML validator. (In older versions it was Ctrl+Alt+V, I think.)
    Birnam wood is come to Dunsinane

  22. #22
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    In IE, you just press [Alt] + [D], [Ctrl] + [C], [Ctrl] + [O], "http://validator.w3.org", [Enter], [Tab] (about ~15 times), [Ctrl] + [V], [Enter]. Simple.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  23. #23
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,745
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    In FF, CTRL+A just highlights everything..all the text, etc.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  24. #24
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by C. Ankerstjerne View Post
    In IE, you just press [Alt] + [D], [Ctrl] + [C], [Ctrl] + [O], "http://validator.w3.org", [Enter], [Tab] (about ~15 times), [Ctrl] + [V], [Enter]. Simple.
    is this supposed to be kidding?

  25. #25
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Apparently so. When I had the web developer toolbar on Firefox it was as easy as [Ctrl] + [Shift] + [A]
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •