SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26
  1. #1
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    should you put a space before your self inclosed tags?

    For instance should it be <hr/> or <hr /> or does it not matter at all, or is there a general practice? I tend to like to add the space myself.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    It doesn't have to have a space, as a rule, but I also like to add the space before the />.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should:

    Quote Originally Posted by http://www.w3.org/TR/xhtml1/#C_2
    Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

  4. #4
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daniel0 View Post
    You should:
    Thanks so I guess it is a w3c recommendation.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  5. #5
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah. Unless of course you wish to set the content-type to application/xhtml+xml.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Correct. <br/> is semantically XHTML correct, but HTML parsers won't understand it. Using <br /> is the best practice when you're dealing with browsers that don't understand XHTML. I'm looking at you, IE!.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which leads us to the fact that you might as well just use HTML instead of XHTML because you'll serve it as such and it will be parsed as such.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    That is unfortunately the case. Because Microsoft refuse to support XHTML, they have effectively killed it.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can find the WC3 recommendation for XHTML 1.0 at w3.org/TR/xhtml1/

    See section 4.6. if you're serving your document as XHTML or C.2. if you're serving it as HTML.

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Basocally if you are using real XHTML then it is <hr/> and if you are not it is <hr>. The space before the slash just allows HTML to discard the invalid slash which may as well not be there in the first place.

    Let's hope IE dies soon so that we can start serving our web pages properly as XHTML.
    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="^$">

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Hear hear!

    I'll get the pitchforks while you arrange the tar. I know of someone who's got the feathers.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #12
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You still have the problem with the error handling when parsing XHTML. The slightest syntactical error will result in an ugly and confusing error message for the user.

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daniel0 View Post
    You still have the problem with the error handling when parsing XHTML. The slightest syntactical error will result in an ugly and confusing error message for the user.
    Yes, but that's the whole point! X(HT)ML must be well-formed which makes it much easier to write an XML parser than an HTML parser (although there are other factors as well).

    If you cannot guarantee well-formed output you definitely shouldn't even consider using an XHTML doctype declaration – even if you intend to serve it as text/html.

    To me, a space before the NESTC+NET delimiters indicates someone who doesn't really know what he or she is doing. But that's just me.
    Birnam wood is come to Dunsinane

  14. #14
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Well formed (X)HTML is definitely far easier to maintain and saves loads of time that would be otherwise lost trying to trace errors caused by the browser deciding that the missing tag (that may be optional in HTML) belongs in a different spot to where you think it ought to be.
    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="^$">

  15. #15
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    Yes, but that's the whole point! X(HT)ML must be well-formed which makes it much easier to write an XML parser than an HTML parser (although there are other factors as well).

    If you cannot guarantee well-formed output you definitely shouldn't even consider using an XHTML doctype declaration even if you intend to serve it as text/html.

    To me, a space before the NESTC+NET delimiters indicates someone who doesn't really know what he or she is doing. But that's just me.
    http://validator.w3.org/check?uri=ht...p%3Ft%3D584341

    And yeah, I know that you are using vBulletin, but the layout is custom so it could've been made using HTML instead of XHTML. Just saying...

  16. #16
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    We all know that the Sitepoint forum doesn't validate.

    I wasn't aware that putting a space was actually not allowed. I guess since I've only seen it in books as " />" (since they were teaching it wrong) I never really thought about it.

    I used HTML 4.01 Strict at the moment anyways, since we still can't use real XHTML reliably.

  17. #17
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    To me, a space before the NESTC+NET delimiters indicates someone who doesn't really know what he or she is doing. But that's just me.
    LOL, Tommy, and I thought this topic made me grumpy. It may not be so much that someone doesn't know what they're doing, but trying to do "the right (or modern) thing" and code in XHTML, and ending up making fundamental compromises such as this thread addresses. You're right, it makes more sense to code in HTML 4.01 Strict and let XHTML hang until the community/industry gets it correlated, but a tremendous amount of "expert" sites push the assumption that only XHTML coding is up-to-date. I know I spent some time trying to teach myself XHTML before learning (in these forums) that I was better off sticking with HTML Strict.

    Off Topic:

    just tweakin' you, buddy. Mrs. Max says hi.


    Off Topic:

    And how come Eric Meyer's site is in HTML Transitional? Like I'm the one to point fingers at him....

  18. #18
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Appendix C of the XHTML standard on making your XHTML compatible to be served as HTML actually specifies that the space is required in that situation. This is because the / is actually invalid when the page is served as HTML and the space is needed to stop it making the preceding attribute invalid as well. The space isn't needed when you are writing real XHTML for example <script type="text/javascript" src="myscript"/> (although adding the space wouldn't allow that XHTML to work as HTML either since in HTML it must have a separate closing tag for scripts).
    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="^$">

  19. #19
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daniel0 View Post
    And yeah, I know that you are using vBulletin, but the layout is custom so it could've been made using HTML instead of XHTML. Just saying...
    FYI, I, personally, have nothing to do with SitePoint Pty Ltd or the forum software. I'm just a volunteer moderator, which is like any other member but with a few extra privileges.

    Quote Originally Posted by samanime View Post
    I wasn't aware that putting a space was actually not allowed.
    It is allowed. It's just not necessary.

    Quote Originally Posted by Black Max View Post
    It may not be so much that someone doesn't know what they're doing
    What I meant was that most people who use pretend-XHTML (XHTML markup served as HTML) don't understand the real difference between XHTML and HTML. As you say, they've been duped into believing that pretend-XHTML is somehow better (more strict, more semantic) than HTML, which is, of course, ********.

    Quote Originally Posted by Black Max View Post
    You're right, it makes more sense to code in HTML 4.01 Strict and let XHTML hang until the community/industry gets it correlated
    In most cases it doesn't make much sense to serve X(HT)ML to clients at all, even if Microsoft should eventually decide to implement support for XHTML.

    Quote Originally Posted by Black Max View Post
    a tremendous amount of "expert" sites push the assumption that only XHTML coding is up-to-date.
    Every source on the Internet should be regarded with a healthy amount of scepticism and distrust. (Yes, that includes my blog, too.) The Web lets anyone publish anything.

    Off Topic:

    Quote Originally Posted by Black Max View Post
    Mrs. Max says hi.
    Hi, Mrs. Max!


    Quote Originally Posted by Black Max View Post
    And how come Eric Meyer's site is in HTML Transitional?
    You'll have to ask him about that. My guess is that he uses a publishing tool that doesn't guarantee pure markup, but it's just a guess.

    Quote Originally Posted by felgall View Post
    Appendix C of the XHTML standard on making your XHTML compatible to be served as HTML actually specifies that the space is required in that situation.
    Appendix C contains HTML compatibility guidelines; it's not a specification. The whole appendix is informative, not normative. So it can't state that something is required, only recommended.

    Quote Originally Posted by felgall View Post
    This is because the / is actually invalid when the page is served as HTML
    No, it's not invalid. It just means something different than in XHTML. (Or, rather, it means the same thing, but uses a different syntax.) Virtually no HTML browser supports the SGML SHORTTAG feature which is declared for HTML (but not for X(HT)ML), so NETs are never used in honest HTML.

    Quote Originally Posted by felgall View Post
    the space is needed to stop it making the preceding attribute invalid as well.
    It doesn't make any attribute invalid. The space is recommended in pretend-XHTML because of some particularly buggy HTML parsers in antique browsers.
    Birnam wood is come to Dunsinane

  20. #20
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    It doesn't make any attribute invalid. The space is recommended in pretend-XHTML because of some particularly buggy HTML parsers in antique browsers.
    That's basically the same thing as being invalid without the space. HTML parsers as you say don't accept the shorttag option and so wouldn't be expecting to see a / there. Netscape 4 (to name one of those "buggy" antique browsers) would then treat the slash as part of the preceding attribute (since without the space there is nothing to say that it isn't) and then that attribute would probably fail to work because of its ending with a slash.
    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="^$">

  21. #21
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    That's basically the same thing as being invalid without the space.
    I strongly disagree. Buggy browsers is something very different from markup specifications.
    Birnam wood is come to Dunsinane

  22. #22
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @AutisticCuckoo: I'm aware you aren't employed by SitePoint. I just chose that particular page to show that this entire forum would be entirely unusable, and thus this discussion wouldn't even take place, if it weren't for the fact that it was incorrectly served as "pretend-XHTML", i.e. (malformed) XHTML served as text/html.

  23. #23
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    I strongly disagree. Buggy browsers is something very different from markup specifications.
    But was Netscape 4 actually buggy. At the time that browser was released the defacto HTML standard was whatever Netscape said it was.
    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="^$">

  24. #24
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    It's buggy when compared with current standards. Back when Netscape 4 came out I don't think XHTML existed.

  25. #25
    SitePoint Enthusiast cssiscool's Avatar
    Join Date
    Feb 2006
    Location
    East Moline, Illinois
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I read somewhere that it is a good idea to add the space because some browsers were in-compatible without the space. But I have no idea if it is true.


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
  •