1

W3C DTD instructions include the following as the very first line of a (X)HTML document:

<?xml version="1.0" encoding="utf-8"?>

I acknowledge the importance of the DOCTYPE declarations that come after this, but what exactly is the point of this first line? Do I need it? W3C validator doesn't seem to care whether it's there or not.

1 Answer 1

1

Its part of specifying what mark up language you have used. When web browsers have to guess, they go into strict mode where the expect you to code the page as specified by the w3c standards.

Without a doctype the browser will go into "quirks mode" which means they might not render the page the way you wish. Also, in general, its just good practice :)

3
  • Yes, that's the point of doctype definition. But I was asking about the <?xml version... line. I just checked about dozen random webpages, and while almost all define the doctype, no site so far seems to include that curious <?xml... line. Sep 13, 2009 at 14:11
  • The <?xml line is a doctype :P
    – Chris Bier
    Sep 13, 2009 at 15:02
  • Humm, actually it's an "XML declaration", and although it's recommended, it's not required if UTF-8 or UTF-8 charset is used: w3.org/TR/xhtml1/#strict . Apparently it's better not to use it: 456bereastreet.com/archive/200904/… Sep 13, 2009 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .