views:

504

answers:

6

Maybe I'm an idiot but I don't quite get what goes in the header of my HTML to use XHTML w/ HTML5. Is this still good and we just add the HTML5 tags?:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html dir="ltr" lang="eng" xmlns="http://www.w3.org/1999/xhtml"&gt;

Or is it <!DOCTYPE html> or what?

Then at A List Apart they say:

If you do go with XHTML 5, remember that your server must deliver the documents with a MIME type of application/xhtml+xml or text/xml.

Please explain to me as if I was stupid :) what that means in a practical sense? "deliver the documents"? Meaning html? What happens to php? What are the steps required to set up your web server this way?

A: 

I would think if it's not already set up you could use apache's AddType directive:

http://httpd.apache.org/docs/1.3/mod/mod%5Fmime.html#addtype:

"The AddType directive maps the given filename extensions onto the specified content type." -- so you would add a .php handler, .html, .shtml, etc as needed.

John Lockwood
+1  A: 

XHTML5 standard is not written yet, so want you want is not achievable. Additionally, HTML5 and XHTML 1.0 are different unrelated standards of HTML.

The mime-type tells the user-agent how to process the current resource. That is different than the doctype declaration, which tells the user-agent what the definition of the current resource is. The mime-type for SGML based HTML is text/html. SGML forms of HTML include: HTML 4, HTML 5, XHTML 1.0, and all earlier versions of HTML. XML forms of HTML must be processed with the application/xml+html mime-type which is only for XHTML 1.1 and XHTML 5.

The biggest differences between the SGML form and the XML form is sloppiness. The SGML form is essentially a text document and is typically regarded as tag soup where validation is often irrelevant and browsers try to do the best they can. In the XML form any error at any point in the code will cause the document to fail at the user-agent and throw an error to the screen, much like any other programming language. In this case the XML form of HTML is treated like an application where code is evaluated for processing opposed to merely a flat text document of characters.

The advantage of using the SGML form is that complete incompetence and ignorance of the technologies is perfectly tolerable. If the browser processes the code then the code is good enough no matter how invalid. The disadvantage to that is that the experience is limited to what the browser can visually process to the end user, which means assisting technologies are at a severe disadvantage. The advantage of the XML form, especially if it is defined using schema instead of doctype, is that the document acts like an application where it is inherently self-aware of its own structure and what its capabilities are. The is always valid or it fails, which means the code is always syntactically uniform, which makes integration of assisting technologies simple and practical. The disadvantage to the XML form is that incompetent and lazy authors cannot publish documents that work correctly. Personally, I do not see that as a disadvantage since its a minimal expectation in absolutely every other regard to any other form of computing.

XHTML5 is part of HTML5. Also, the "SGML form" is a fable, there's only an "HTML serialization".
Ms2ger
HTML serialization is SGML form. XHTML5 is not part of HTML5. XHTML5 is intended to be the XML syntax compatible form of HTML5. You might need to read up about what SGML and XML are.
@austin: HTML5 is explicitly not SGML. XHTML5 is defined in the HTML5 specification as XML serialization of HTML5.
porneL
@porneL then what language is HTML5 based upon? XHTML5 does not yet exist except in name only. It is intended to be an XML representation of HTML5, which is not likely given that HTML5 is a massive direction away from XML compared to previous forms of HTML.
+1  A: 

Doctype for HTML5/XHTML5 is: <!DOCTYPE html> & in XHTML 5 you are required to specify the namespace <html xmlns="http://www.w3.org/1999/xhtml"&gt;.

Content type can be set in meta tag, just as in any other html/xhtml document, using content attribute, like

<meta content="text/html">

As far as header is concerned, it is recomended to use text/html for HTML5 [and any other HTML]: (.html, .htm) or application/xhtml+xml, application/xml for XHTML5 [or any other XHTML]: .xhtml, .xht, .xml.

If server doesn't automatically detect proper content type and set it as it should (You can check Response Headers using Net panel in Firebug), it can be set in php, using header function, like this:

header("Content-Type: text/html");

You can also negotiate content on Apache server.

Here is what WHATWG Wiki says on mime types in (X)HTL5:

The XHTML serialization must be served using an XML MIME type, such as application/xhtml+xml or application/xml. Unlike XHTML1, XHTML5 must not be served as text/html.

Using the incorrect MIME type (text/html) for XHTML will cause the document to be parsed according to parsing requirements for HTML. In other words, it will be treated as tag soup. Ensuring the use of an XML MIME type is the only way to ensure that browsers handle the document as XML.

For some light reading on the subject, you should check Wikipedia entry on HTML5 for more details, as well as WHATWG FAQ. If you prefer heavy reading, go for HTML 5 last draft standard.

Finally, now there are few more differences between HTML and XHTML you should check out.

Good luck!

Krule
<meta content="text/html"> doesn't make sense. You probably want to refer to <meta charset="UTF-8">, which is used to declare the encoding of your document.
Ms2ger
While charset should be refered in order to set document encoding, meta content is in html5 standard, just as it is in all other html/xhtml standards. It is used to define mime type of the document.
Krule
+3  A: 

To correctly serve HTML5 document, you don't have to do anything unusual. Servers default to content-type appropriate for HTML5. Just start your documents with:

<!DOCTYPE html>
<meta charset=UTF-8>

(meta is not strictly necessary, but it's a good idea to use it, otherwise you might get Windows 1250 encoding or something worse).

Only serving of XHTML5 requires extra hoops to jump through. You have to send Content-Type: application/xhtml+xml header. There is no way to do it from within document with any kind of DOCTYPE or <meta>. It absolutely has to be out-of-document HTTP header. How to do that depends on server/language you use. In PHP you'd do:

header("Content-Type:application/xhtml+xml;charset=UTF-8");

However, you probably don't want to do that, because IE doesn't support XHTML5 at all. Stick to HTML5, which has much better compatibility with legacy UAs.

porneL
A: 
Dwight Vietzke
A: 

Better late than never, I always say. Here is the answer I was looking for way back when:

...when served as 'application/xhtml+xml' from the server, will tell the browser that it should parse the page using as xhtml and not just html.

Dwight Vietzke