SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2008
    Location
    Hot Springs, Montana
    Posts
    195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    closing empty elements

    I notice that all my self-closing tags " /> are setting off validation warnings in my html 4.01 doc.

    In regard to the meta statement, am I reading correctly that I should be avoiding it all together in a 4.01 document?

    # Warning Line 9, Column 79: NET-enabling start-tag requires SHORTTAG YES

    /wui_stylesheet.css" type="text/css" />

    The sequence <FOO /> can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates the tag <FOO (with an implied '>'). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.
    In regard to other empty elements, like many of may images, should I be leaving off the end greater-than sign after the slash throughout the document (ie., within the body)?
    Code HTML4Strict:
    <img src="images/interface_140px.jpg" width="140px" height="173px" /

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2008
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You always need a closing tag! They are talking about '/', not '>'.

    Code HTML4Strict:
    <img src="images/interface_140px.jpg" width="140px" height="173px">

  3. #3
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    You're using a HTML, not a XHTML doctype, ergo you need to write in the HTML syntax. Remove the slash from all your self-closing tags and close them simply with > and you should be fine.

    HTML

    Code HTML4Strict:
     
    <img src="myimage.jpg" alt="my image">

    XHTML

    Code HTML4Strict:
     
    <img src="myimage.jpg" alt="my image" />

    Edit: Or what Kyle W said. Sorry, didn't see your post when writing mine.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  4. #4
    SitePoint Zealot
    Join Date
    Jan 2008
    Location
    Hot Springs, Montana
    Posts
    195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. After reading these replies I just reread this piece to see how I had become confused.... made better sense this time. http://www.cs.tut.fi/~jkorpela/html/empty.html

    Again, thanks.

  5. #5
    SitePoint Addict seo-neon's Avatar
    Join Date
    Aug 2008
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must always close your element or it will look nasty on your webpage...

  6. #6
    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 seo-neon View Post
    You must always close your element or it will look nasty on your webpage...
    That's utterly wrong.

    In HTML the end tags for EMPTY elements are forbidden. Writing <br></br> is invalid.

    In XHTML it's different. That's not HTML, but XML. And XML requires well-formed markup so every element must have a closing tag. It also provides the shorter version with null end tags (often called self-closing tags), so you can write <br/> instead of <br></br>.

    Note, however, that this means something completely different in HTML. HTML, in theory, also allows null end tags, but uses a different syntax for it. Browsers don't support this, though, so it's not usable in the real world. But writing <abbr/HTML/ instead of <abbr>HTML</abbr> is valid HTML even if it's not supported.

    XML (including XHTML) only allows null end tags for empty elements, so <abbr/HTML> is not valid XHTML.
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2008
    Location
    Hot Springs, Montana
    Posts
    195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've had a minute to experiment and have learned now through trial-and-error that my original reading was correct: the w3c validator WAS telling me to remove the greater-than sign from the empty elements in the head. And... I draw warnings when I leave the forward slash.... what's more, I draw warnings with the lesser-than sign before my title element. And, I'm reading that some browsers won't recognize a valid mark-up. (Wow. This is like politics. I wonder why?)

    So, in regard to strict html 4.01, particularly in regard to empty elements in the head, what should a sensible person do? (Not to imply sensibility on my part.)

    BTW, in the body element, would a break simply look like the opening tag in an xhtml element? ie. <br> with no closing tag?

    Forgot to mention that merely removing the slashes returned no error but did return warnings, which got me on this track in the first place. Also, I'm sticking with that approach now as it seems to be the path of least resistance.

  8. #8
    SitePoint Zealot eLaw's Avatar
    Join Date
    Nov 2008
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's mainly about img tag ..
    It works fine without / at the end , but it's marked as an error if you try to validate ..
    For strict validation the spaces matters also , like <br /> for example ..

  9. #9
    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 rbfree View Post
    I've had a minute to experiment and have learned now through trial-and-error that my original reading was correct: the w3c validator WAS telling me to remove the greater-than sign from the empty elements in the head.
    No, it was telling you to remove the slash characters. As I said, '/>' means something very different in HTML and XHTML.

    Quote Originally Posted by rbfree View Post
    So, in regard to strict html 4.01, particularly in regard to empty elements in the head, what should a sensible person do? (Not to imply sensibility on my part.)
    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Document Title</title>
        <link rel="stylesheet" type="text/css" href="/style.css" media="screen,projection">
      </head>
      <body>
        <!--Body content-->
      </body>
    </html>

    Quote Originally Posted by rbfree View Post
    BTW, in the body element, would a break simply look like the opening tag in an xhtml element? ie. <br> with no closing tag?
    Yes, the end tag is forbidden in HTML for element types declared as EMPTY in the DTD, i.e., element types that can never have any content.

    Quote Originally Posted by eLaw View Post
    For strict validation the spaces matters also , like <br /> for example ..
    Sorry, but that's incorrect. The space is completely unnecessary in X(HT)ML. The only reason it's recommended in Appendix C of the XHTML 1.0 specification is that when serving XHTML markup as text/html, some ancient HTML-only browsers may choke on the slash character if it's not preceded by white space.

    It has nothing to do with XML or strictness. It's just a way to avoid a bug in some browsers that virtually no-one uses anymore, when serving XHTML markup in a way that doesn't really deliver it as XHTML at all.

    In real XHTML (served as an application of XML) the space is utterly redundant and just shows that the author is a beginner.
    Birnam wood is come to Dunsinane


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
  •