The <?xml version="1.0"?> Declaration for HTML


ATTENTION: THIS PAGE IS Valid HTML 5 AND IS BEST VIEWED WITH HTML 5 - Please upgrade your browser or download one of the HTML 5 compatible browsers such as Mozilla Firefox, Chrome, Opera or IE 9 (March 14, 2011 or later). For more information see HTML 5 browsers.

If you find this helpful, please click the Google +1 Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.)

PDF mobile

The <?xml version="1.0"?> Declaration for HTML

The XML declaration is one of the declaration tags in HTML and is the very first line of code in an HTML document. The <?xml?> declaration at the top of an HTML document indicates that the document is in XML or polyglot format. It is an SGML declaration that determines:

  • what characters can appear in the document,
  • how those characters are to be interpreted as text and delimited elements, and
  • that there are no external XML declarations, since there is no DTD in HTML 5
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

The XML declaration may be ignored when the document is being parsed as HTML, but is relevant when:

  • the document is being parsed as xHTML, the XHTML-compatible serialization of HTML based on XML
  • the document is being parsed as pure XML

<?xml?> Declaration Syntax

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet ...?>
<!DOCTYPE html>
<html xmlns="">
Rules for coding the xml declaration for HTML 5
  • Code the <?xml?> tag on the first line of the document, before anything else. When generating code using server-side scripting languages such as PHP, it should be the first thing that is output, after the HTTP headers.
  • The xml declaration starts with the characters <?, which indicates that the markup is a SGML declaration rather than an HTML tag.
  • Following the <? delimiters, code the letters xml in lower case.
  • Include a version attribute to indicate the characters that can be used in element names, and an encoding attribute to specify the character encoding of the document.
  • Include a standalone attribute with the value "yes" to indicate that the document is a standalone document and is not to be affected by any external declarations.
  • The xml declaration ends with the characters ?>.
  • The <?xml?> tag does not have a matching end tag.

The following rules apply to the entire HTML document, based on the <?xml?> declaration:

  • If the version attribute specifies XML version 1.1, any characters in the range &#x7f; through &#x9f; must be encoded as HTML character entities, in addition to all characters in the range &#x01; through &#x1f;. The NUL character &x#00; is not permitted in either version of XML.

<?xml?> Declaration Attributes

version The version attribute is coded as version="1.0", which indicates the document follows the XML version 1.0 syntax. The document should be coded to be "well-formed", even if it is not an entirely "valid" HTML document.

The encoding attribute indicates what character encoding has been used to encode the HTML document as a file or byte input stream. Most importantly, among other things, this determines how many bytes of raw data are consumed to compose each character of the decoded document.

One advantage of using encoding="UTF-8" or encoding="UTF-16" is that IRI references can be used without having to escape all of the non-ASCII characters in the query part.

standalone="yes" The standalone attribute with the value "yes" indicates that the document is a standalone document. When recognized as an HTML 5 document, the parser should not look for any external declarations since there is no DTD in HTML 5, in which case the standalone attribute is irrelevant. If a parser tries to process the document as an older version of HTML having a DTD or when processed by an XML parser, standalone="yes" indicates that it should ignore any external declarations, such as entity declarations or assumed attribute values.

<?xml?> Declaration Examples

Examples of the xml declaration in HTML 5
<?xml?> declaration for XML version 1.0

The <?xml?> declaration appears at the very beginning of an HTML document:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/site-template.xsl"?>
<!DOCTYPE html>
<html xmlns="">

It is recommended that the encoding be specified using the preferred (MIME) name as specified in the IANA's Official Names for Character Sets. The standalone attribute can also be coded with the value yes, since the default is "no". Some examples:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<?xml version="1.0" encoding="US-ASCII" standalone="yes"?>
<?xml version="1.0" encoding="EUC-JP" standalone="yes"?>
<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<?xml version="1.0" encoding="ISO-10646-UCS-2" standalone="yes"?>
<?xml version="1.0" encoding="ISO-10646-UCS-4" standalone="yes"?>

If the standalone attribute is omitted it does not matter unless the HTML browser would normally try to use external declarations, in the form of the HTML DTD, to interpret the document. standalone="yes" prevents it from using those external declarations, which would be for older versions of HTML rather than HTML 5 and later.

<?xml?> declaration for XML version 1.1

XML version 1.1 added support for record-oriented files, such as those used on mainframe systems, by including the next line (&#x85;) and line separator (&#2028;) characters to the list of valid line-ending characters.

<?xml version="1.1" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="/site-template.xsl"?>
<!DOCTYPE html>
<html xmlns="">

XML version 1.1 also provides more generic language support by allowing almost all Unicode characters in element type names, attribute names, enumerated attribute values and processing instruction targets, but since these items are defined by the HTML specifications, HTML documents do not take advantage of this new feature.

Changes in HTML 5 - <?xml?> Declaration

What's new in HTML 5

The <?xml?> declaration was introduced in the 2000 W3C standard version of HTML. However, many documents on the web are still coded without it and therefore may fall back to the older 1997 HTML version 4 standard, so going forward you should make sure that any HTML pages start with an <?xml?> declaration.

Differences between HTML 5 and earlier versions of HTML
  • The <?xml?> declaration does not appear in HTML documents conforming to the 1997 HTML 4 standard. For the HTML versions based on the 2000-2010 Recommendations from the W3C HTML Working Group, the <?xml?> declaration was optional. For HTML version 5 documents, it's use is recommended so that the document is handled properly when being parsed as either xHTML or pure XML.
  • Since there is no DTD in HTML 5, there are no external XML declarations that might change how the HTML document is processed. In previous versions of HTML, for example, a DTD could possibly change the default value of an HTML attribute. In HTML 5, things like default attribute values are always determined by the HTML specification.

Valid HTML 5