HTML Document Syntax

This section describes the HTML document syntax. A HTML document must have a DOCTYPE declaration and an 'html' element.

At a high level, the HTML document syntax is very simple for the HTML5 standard as described below.

An HTML document must consist of 6 parts in the given order:

  1. BOM character - Optional. If provided, the BOM (Byte Order Mark) character, Unicode of U+FEFF, specifies how characters are encoded in the document.
  2. Comments and white space - Optional. If provided, comments and white spaces will be discarded by the browser. A single comment must be coded as "<!-- ... -->".
  3. DOCTYPE declaration - Required. The DOCTYPE declaration identifies the HTML version of the document. For HTML5 document, "<!DOCTYPE html>" should be used.
  4. Comments and white space - Optional.
  5. Root element - Required. The root element, "html", holds the entire HTML document content.
  6. Comments and white space - Optional.

Here is a simple example of HTML document that matches the above HTML document syntax requirements:

<!DOCTYPE html>
<!-- HTML5_Document_Syntax_Example.html
 - Copyright (c) 2014, HerongYang.com, All Rights Reserved.
-->
<html>
 <!-- "html" is the root element -->
 <head>
  <title>HTML5 Document Syntax Example</title>
 </head>
 <body>
  Hello World!
 </body>
</html>
<!-- End of the document -->

Last update: 2014.

Table of Contents

 About This Book

 Introduction of HTML

 Introduction of HTML5 Features

 HTML Document Structure and Content

HTML Document and Elements Syntax

HTML Document Syntax

 Document Character Set and Encoding

 Entering Comments in HTML Document

 Opening and Closing Tags of Elements

 Using Nested Elements

 Specifying Element Attributes

 Specifying Element Contents

 Element Content Syntax Types

 Using Whitespace Characters

 Using Character Entity References

 Using Numeric Character References

 References

 PDF Printing Version