in reply to For valid HTML

I don't see any real issue with using a trailing slash, especially with a doctype of 4.0 transitional that tells us to expect a jumble of tag soup. Maybe we ought to move up to 1999 and use 4.01 since it supersedes 4.0.

Just for kicks, I ran the w3c validator against the front page and got 115 Errors and 199 warnings. Most of the problems were because the validator gets confused about how to parse the many trailing slashes and a few were cruft from HTML 3.2. The actual warning (NOT error) for the link tag was

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.
FWIW, a simple <br /> validates as HTML 4.01 Transitional as a snippet in the validator.

At one point it looked like the web was (theoretically) headed towards XHTML but now it looks more like HTML 5. The WHATWG wiki article on HTML vs. XHTML says

Void elements only have a start tag; end tags must not be specified for void elements, and it is impossible for them to contain any content. A trailing slash may optionally be inserted at the end of the element's tag, immediately before the closing greater-than sign.
Either way, the trailing slash will probably be at least optional.

I do feel your pain though as I'm also quite pedantic about the HTML I generate.

Replies are listed 'Best First'.
Re^2: For valid HTML
by ikegami (Patriarch) on Apr 04, 2010 at 23:46 UTC

    Either way, the trailing slash will probably be at least optional.

    At most optional. The slash being treated as optional is the best possible result, not the worst. The possible outcomes range from "incorrectly used and ignored" to "incorrectly used and gives an error". (Browsers don't support the correct use.) The OP's browser is apparently somewhere in the middle of that range since it ignores the error for rendering purposes while discretely notifying the user of the error ("red circle with an X in it").

    especially with a doctype of 4.0 transitional that tells us to expect a jumble of tag soup

    It sounds like you're saying transitional documents don't have to be well-formed, and that's not true.

      Actually, <BR/> would be the start of a SHORTTAG construct (ending with the next slash). It's not supported by most mainstream browser, but it's a valid SGML construct, and the HTML DTD doesn't prohibit it (unfortunally). See SGML features with limited support.

        Actually, <BR/> would be the start of a SHORTTAG construct (ending with the next slash).

        "Actually"? Not only do I know that, I covered that case. ("Browsers don't support the correct use.")

        but it's a valid SGML construct, and the HTML DTD doesn't prohibit it (unfortunally)

        Not quite. BR can't have a body. <BR// might be valid HTML, but <BR/<.../ is not.

      The slash being treated as optional is the best possible result, not the worst.

      That's a matter of opinion, I'm sure some people would rather see XHTML win out over HTML 5.

      It sounds like you're saying transitional documents don't have to be well-formed, and that's not true.

      Oh really? The front page of perlmonks renders just fine in my browser but it's not even close to a well-formed document. To clarify, I believe there are two ends of the spectrum: what works and what is correct. Many websites work just fine with broken HTML. Many times, the HTML is intentionally broken to support browsers that don't support standards. I really don't mean to criticize perlmonks here, it works and that's all I ask, but the site doesn't exactly validate.

      Myself, I strive to write correct code in any language and to comply with any applicable standards to the best of my ability.

        That's a matter of opinion

        No opinion. It really is illegal HTML, and that working to not working is the range of behaviour.

        Ok, I suppose saying having it work is the best behaviour is an opinion. But seriously? You'd say browsers throwing errors at the slash would be better? For whom??

        I'm sure some people would rather see XHTML win out over HTML 5.

        That makes no sense. They're orthogonal. HTML 5 has an XML serialization too.

        Oh really? The front page of perlmonks renders just fine in my browser but it's not even close to a well-formed document

        I was expecting a counter example after "Oh really?". You need to show that the page wouldn't be rendered fine if the strict DTD was specified to contradict me. Browsers expect a tag soup for HTML docs no matter what DTD (if any) is specified.

        To clarify, I believe there are two ends of the spectrum: what works and what is correct.

        Earlier you were disagreeing with my opinion that having bad HTML work anyway is the best behaviour. Now you agree with it. What are you trying to say?