Forum Moderators: open

Message Too Old, No Replies

XHTML strict doctypes and headers

what do you have to have above the header

         

J64sqs

9:50 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



So, I was told that for strict xhtml I should start my page like this:

<?xml version="1.0?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

But, I've heard that that first line can make the page explode in old browsers. And I've also found that the w3c validator will still say the page is valid if I start it like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

So, is it okay to use this second option, or should I really be using the first option?

encyclo

10:02 pm on Nov 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's fine to use the second option, because the XML prolog is optional according to the specifications. The problem with the prolog is Internet Explorer 6 reverts to "quirks mode" rather than the more appropriate "standards-compliance mode" when the doctype is not on the first line.

The XML prolog can be used to define the charset of the document: however, it is usually better practice to define this in the HTTP header instead. The prolog only becomes truly relevant when you are serving your document with the mime type

application/xhtml+xml
and you are strictly following the standards.

J64sqs

10:47 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



I assume you are calling <?xml version="1.0?> the XML prolog.

What is the <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> called? Or what is this stuff in the html tag doing?

encyclo

3:10 pm on Nov 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The
xmlns
attribute is for the XML namespace: it is usually present in conforming XHTML documents. It is not vital unless, again, you are serving
application/xhtml+xml
and perhaps mixing different namespaces. I would leave it in.

The

xml:lang
and
lang
attributes are the XML method and HTML method respectively for declaring the document language (in your example, English). It is good practice to always declare the language in this way.