2

I may be mistaken, but I thought since HTML was straying from it's roots as XML, there was a push to make HTML more like XML again. This is in the sense of leaving styling up to something else (like CSS) and syntax (such as putting the closing / in a tag). For example, XHTML strict doesn't validate if there is any inline CSS; all CSS needs to be external. With HTML 5 this doesn't really seem to be the case—for example, see this question about <br> vs <br />. Also there are tags for media like <audio> and <video>.

So, here's my question: When coding HTML, should one err on the side of XML or go with the minimal of the newest HTML standards outline? For example, if the standard says a tag doesn't need a closing slash, don't include it?

The answers to the linked-to question are good, but they explain what can be done, not what should be done.

Community
  • 1
  • 1
Celeritas
  • 14,489
  • 36
  • 113
  • 194
  • 4
    HTML has never had its roots in XML. It's rooted in SGML. XML came later, after which XHTML was created. And strict XHTML *does* validate with inline styles and ` – BoltClock Dec 04 '14 at 04:28
  • 1
    See also: ["XHTML5"](http://www.w3.org/TR/html5/the-xhtml-syntax.html#the-xhtml-syntax), and [polyglot markup](http://www.w3.org/TR/html-polyglot) (both related to HTML5) – BoltClock Dec 04 '14 at 04:32

1 Answers1

1

XHTML is dead; the XHTML 2.0 working group charter at the W3C expired in 2009 and was not renewed. The current W3C standard is HTML5, which was adopted as a "Recommendation," i.e. a standard, on October 28, 2014. I don't see any point in hewing to the XHTML standard, although I do it from force of habit. The HTML5 validator and HTML5-compliant browsers tolerate self-closed tags rather well.

The <audio> and <video> tags actually are supposed to be in pairs because they enclose content, so it is incorrect to make them self-closing.

The one thing I do suggest is not to go wild with case-insensitivity. I'm sticking to all lowercase.

Someone else posted a link, now withdrawn, which pointed out that making your HTML5 also be well-formed XML allows it to be processed by XSLT. That might be one good reason to stick with lowercase names and self-closing tags. Of course, you'd have to make your attributes XML compliant, too, which is a major pain.

Bob Brown
  • 1,463
  • 1
  • 12
  • 25
  • That's a very valid answer I was unaware of. Could you please say what makes you say that XHTML is dead? – Celeritas Dec 04 '14 at 04:20
  • Could you elaborate on "making your attributes XML compliant"? –  Dec 04 '14 at 08:04
  • 1
    You can not use the short syntax. In XML you always have to use `attribute="value"` even for boolean attributes. – ThW Dec 04 '14 at 09:33
  • 1
    @BalusC: Perhaps instead of "dead" I could have said, "no longer under development by the W3C." If one wants to use the new semantic tags, the new input tags, native audio and video, that's HTML5. You can write HTML5 so that it is *also* well-formed XML, but that *isn't* XHTML. – Bob Brown Dec 04 '14 at 16:54
  • Actually, it ***is*** OK to refer to the XML serialization of HTML5 as [XHTML](http://www.w3.org/TR/html5/the-xhtml-syntax.html). – DavidRR May 04 '15 at 15:50
  • @DavidRR: Because I teach this stuff, if you have a citation, please post it. I try to be precise in class, and if I'm wrong, I need to knock it off. Thanks! – Bob Brown May 04 '15 at 21:14
  • @BobBrown: Did you not visit the W3C link that I included in my comment? You'll see that it references chapter 9 of the HTML5 recommendation, [The XHTML syntax](http://www.w3.org/TR/html5/the-xhtml-syntax.html). – DavidRR May 05 '15 at 12:04
  • 1
    @DavidRR: Nope, I missed it. I apologize, and thank you. – Bob Brown May 05 '15 at 21:31