What's the real content type of XHTML?

J

John Salerno

Right now the recommendation is to use content-type="text/html" in the
<head> tag, but is that really correct? Should it be
application/xhtml+xml? I'm wondering if the content-type attribute is
supposed to parallel the way it's being served (or the proper way to
serve it, meaning eventually we'd have to replace this attribute on any
XHTML files being written today).
 
S

Steve Pugh

John said:
Right now the recommendation is to use content-type="text/html" in the
<head> tag,

No, the recommendation is to set the HTTP content-type header to
text/html
This has nothing to do with <head> or any other html element.

Whilst the meta tag http-equiv="content-type" may be used by browsers
to extract character encoding information under some circumstances it
can not be used to extract content type as the browser will only look
for meta tags inside files it already knows to be HTML. (Though I
suppose IE might do some of its infamous guessing by peeking at the
first few lines of the file....)
but is that really correct? Should it be
application/xhtml+xml? I'm wondering if the content-type attribute is
supposed to parallel the way it's being served

If you want to use the meta tag for some reason then you should have
the same information in the meta tag that you have in the real HTTP
header.
The one exception would be if you are briefly using a server for some
quick demo and that server doesn't let you set the charset parameter at
all (i.e. it serves content-type headers with no charset parameter)
then you can set the character encoding in the meta tag and hope that
browsers use it.
(or the proper way to
serve it, meaning eventually we'd have to replace this attribute on any
XHTML files being written today).

Serve the correct HTTP content-type header - which is text/html for
HTML, and in the real world of IE domination, for Appendix C XHTML 1 -
and optionally include a meta tag with the same values.

Steve
 
B

Benjamin Niemann

John said:
Right now the recommendation is to use content-type="text/html" in the
<head> tag, but is that really correct? Should it be
application/xhtml+xml? I'm wondering if the content-type attribute is
supposed to parallel the way it's being served (or the proper way to
serve it, meaning eventually we'd have to replace this attribute on any
XHTML files being written today).

The content-type (in the META element) itself is meaningless - the browser
has to know it *before* it could parse the document and get it from the
META element... (only the charset parameter may be used by the browser).

The proper way to specify the content-type for a document it to set the
correct HTTP header.
XHTML1.0 *should* (in the RFC meaning: *do it* - unless you really know what
happends or may happen, if you don't) have the content-type
application/xhtml+xml, but it *may* be served as text/html, if it complies
to Appendix C of the spec.
 
J

John Salerno

Steve said:
No, the recommendation is to set the HTTP content-type header to
text/html
This has nothing to do with <head> or any other html element.

Sorry! I meant the <meta> tag, not <head>.
 
A

Andy Dingley

John said:
Right now the recommendation is to use content-type="text/html" in the
<head> tag, but is that really correct?

No, it's almost totally bogus. Use the HTTP headers, not the
http-equiv <meta> in the <head>.

The only good thing to do with putting them in the head instead of the
headers is if you're working with web documents as files a lot and you
have funny character encodings that need a non-default encoding. This
is obscure as both something to want to do, and also as a combination
of characters and encodings.

As to text/html vs. application/xml-stuff, then that's our regularly
scheduled programming. Every night at 6:30, just between the Simpsons
and Trek re-runs.
 
J

John Salerno

Andy said:
No, it's almost totally bogus. Use the HTTP headers, not the
http-equiv <meta> in the <head>.

I probably should have picked up on this by now, but what are "HTTP
headers"? Is that something in the HTML file itself, or is it how the
page is being served (i.e. not easily editable)?
 
D

David Dorward

John said:
I probably should have picked up on this by now, but what are "HTTP
headers"? Is that something in the HTML file itself, or is it how the
page is being served (i.e. not easily editable)?

The browser makes an HTTP Request to an HTTP server which sends an HTTP
Response. This response consists of a number of headers followed by the
message body. When requesting HTML documents, the message body consists of
the (entire) HTML document.

It is generally pretty easy to adjust the headers sent providing you have a
reasonable hosting package.

That said, XHTML as text/html is silly and XHTML as application/xhtml+xml is
badly supported (e.g. IE doesn't try to render it at all. Firefox can't
deal with it as well as text/html.)

Sticking with HTML 4.01 Strict on the client side is still the best choice
in almost every case.
 
J

John Salerno

David said:
The browser makes an HTTP Request to an HTTP server which sends an HTTP
Response. This response consists of a number of headers followed by the
message body. When requesting HTML documents, the message body consists of
the (entire) HTML document.

It is generally pretty easy to adjust the headers sent providing you have a
reasonable hosting package.

That said, XHTML as text/html is silly and XHTML as application/xhtml+xml is
badly supported (e.g. IE doesn't try to render it at all. Firefox can't
deal with it as well as text/html.)

Sticking with HTML 4.01 Strict on the client side is still the best choice
in almost every case.

That's what I suspected. The other day I set up application/xhtml+xml on
my server, so that would be the HTTP Header when an .xhtml file is sent
back?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top