1

When XHTML came around I moved to following all the necessary rules like everybody, closing empty tags:

<meta />
<br />
<img />

always using lowercase, always putting attribute values in quotes, avoiding attribute minimisation:

checked="checked"

...and so on.

Now, since the move to HTML5 as I understand it you can still utilise those same standards within HTML5, as there could be XHTML within HTML4 or XHTML within HTML5, basically meaning you could still utilise XHTML's rules within HTML5 - it's not one or the other.

Now, the reason I am talking about this is because I started wondering about the xmlns attribute of the html element that I have been using, that being: xmlns="http://www.w3.org/1999/xhtml".

Now as I understand it this became a requirement with the introduction of XHTML but I have continued using it within HTML5.

So my question is, if I wanted to keep using XHTML's standards within HTML5 do I have to continue inserting this attribute into my html element?

...and if so, I would assume if I coded inavlid XHTML such as <br> then it would become invalid just like it previously would?

Brett
  • 19,449
  • 54
  • 157
  • 290
  • 1
    You can't maintain double standard in a single document. – Klanto Aguntuk Jul 25 '18 at 18:21
  • @OptimisticWalker I'm not sure what you mean. – Brett Jul 25 '18 at 19:01
  • 1
    you have to either declare your document as `XHTML` or `HTML5`. You could still utilize some XHTML's rules within HTML5 but only the ones are supported by HTML5 standard and vice versa. – Klanto Aguntuk Jul 25 '18 at 19:07
  • That doesn't make sense, as I said, there is XHTML within HTML5 as there was XHTML in HTML4, it's not "use XHTML *or* HTML5. – Brett Jul 25 '18 at 19:24
  • @Brett That is not correct. XHTML is not HTML. You use either HTML or XHTML. You cannot use "XHTML in HTML" or vice versa. And if it is XHTML, you need the slashes, the `xmlns` attribute, the `checked="checked"` etc. In HTML, you do not. – Mr Lister Jul 26 '18 at 06:41
  • And to your question, "_if_ I wanted to keep using XHTML's standards within HTML5 do I have to continue inserting this attribute into my html element?" the answer is no, they are optional in HTML. Putting an `xmlns` attribute in doesn't mean you also have to put slashes in. Because putting an `xmlns` attribute in does not mean the file type gets changed from HTML to XHTML! – Mr Lister Jul 26 '18 at 06:47
  • On the other hand, if you want to use XHTML syntax with the HTML5 vocabulary and content model, you *must* serve your page with the `application/xhtml+xml` content type, and if you do, then you must also use the `xmlns` attribute. – Alohci Jul 26 '18 at 06:51
  • @OptimisticWalker - The bimorphic standard for HTML5, describing how to create a single HTML5 document that supports both HTML and XHTML syntaxes is no longer maintained, because there is no point in creating such a document now that all modern browsers support both syntaxes. But it is entirely possible to create documents that are valid for both syntaxes of HTML5. – Alohci Jul 26 '18 at 07:06
  • @Alohci Well, there are still differences. It's not always possible to use the polyglot markup I think you're referring to, and have it come out the same in XHTML and HTML. E.G. in HTML, `<![CDATA[ .. ]]>` sections don't work. In XHTML, named entities like `é` don't work (not if you use the XHTML5 doctype anyway). Etc. But I think we're moving outside the scope of the OP's question now. – Mr Lister Jul 26 '18 at 07:12
  • @MrLister - Sure there are features of both syntaxes that don't work in the other. So if you were creating a bimorphic document, you'd need to avoid use of those features. There are ways around no CDATA sections and one can always use numeric character entities rather than named ones. But like I say. There's no point in creating such a document any more. Just choose your preferred content type and syntax and stick to it. – Alohci Jul 26 '18 at 07:25
  • @MrLister - And yes I meant "biglot" or "polyglot" if you prefer, rather than "bimorphic" – Alohci Jul 26 '18 at 07:35
  • Perhaps you misunderstood me; when you're using XHTML, it's still HTML, you're just using XML syntax; same with HTML5, it's still HTML5, but you would be using XML syntax with it, hence the name XHTML or "XHTML5". – Brett Jul 26 '18 at 13:40
  • @Brett, there is no such document standard in `html` named `XHTML5`. You have to treat the document either as `XHTML` or `HTML5`. Thanks, – Klanto Aguntuk Jul 26 '18 at 17:06
  • 1
    @OptimisticWalker I know that, I'm just saying it can be HTML5 code, but using XML syntax, so, "XHTML5. Perhaps this will explain it better: https://mathiasbynens.be/notes/xhtml5 – Brett Jul 26 '18 at 17:14
  • @Brett, yes you can say so but you can't declare that for a valid html page unless it is documented. – Klanto Aguntuk Jul 26 '18 at 17:26
  • @Brett, example of `XHTML` document declaration ` ` example of `HTML5` document declaration ` `. Thanks, – Klanto Aguntuk Jul 26 '18 at 17:34
  • 1
    @OptimisticWalker I'm not talking about the doctype here, I'm quite aware of both of these and that one is for XHTML and one is for HTML5. However, according to that link you can still use the HTML5 one for "XHTML5", but it isn't really needed. – Brett Jul 26 '18 at 20:41
  • @Brett Like I said earlier, you can use _some_ XML features in an HTML document, because they're optional (for instance, the xmlns attribute, although it doesn't do anything), but not all XML features (for example, a <![CDATA[ section in a HTML file is treated as some kind of comment rather than text). If that doesn't answer your question, I don't know what your question is. – Mr Lister Jul 27 '18 at 06:21
  • @Brett, I have my up vote for you as you posted your question too seek some clarifications about an issue you are confused about. – Klanto Aguntuk Jul 27 '18 at 21:29
  • @OptimisticWalker Haha thank you! :) – Brett Jul 28 '18 at 16:57

1 Answers1

1

Objectively

In HTML 5 it is not strictly required to close certain tags, use lowercase attributes and values, and avoid attribute minimisation. However, the markup will be valid whether you do or not.

Like all previous version, HTML 5 does not allow end-element tags for img, br and other self-closing elements, but will merely tolerate those as part of error recovery that is part of the specification.

HTML 5 does not require a reference to a DTD (Document Type Definition). This is because HTML 5 is no longer based on SGML. Browsers cannot parse HTML 5 as SGML for compatibility reasons.

Furthermore, HTML 5 - like HTML 4 - can not contain an xmlns (XML namespace) attribute, because it's markup does not describe XML.

There is also an answer about the XHTML5 specification. In short, XHTML was abandoned for HTML5 and now only refers to a syntax. Additionally you can still use HTML5 in XML serialization mode. For this the document must be served as application/xhtml+xml.

Subjectively

You do not have to throw away the practices you have learned, writing valid XHTML. There is no point to avoiding attribute minimisation anymore, but closing empty tags and always using lowercase could make a great difference in code readability, depending on the preferences of your team.

Webber
  • 4,672
  • 4
  • 29
  • 38
  • IMHO this answer needs further qualification. HTML5, like all previous version, does **not** allow end-element tags for `img`, `br`, and other "void" elements, but will merely tolerate those as part of error recovery that HTML5 made part of the spec, based on what browsers were doing de-facto. – imhotap Aug 01 '18 at 16:59
  • @imhotap i've added your input (2nd paragraph) – Webber Aug 01 '18 at 18:19