Basic HTML Document Structure

There are almost no minimum requirements for an HTML document. A file with the .html file extension and containing a single HTML element will still be readable in the average browser.

<h1>Heading</h1>

The white space within the document doesn’t matter to the browser either. It could be written all on one line, or with inconsistent spacing and it would still display properly. It’s good practice to properly nest and indent the elements so the other people have an easier time reading the code.

<!DOCTYPE html>
<html lang="en">
  <body><h1>
        Heading
      </h1><p>The 
      white 
        space 
      within 
          the document doesn&rsquo;t
           matter</p>
<p>This
        is
                    horrible but looks
      fine in
      a browser.</p>
  </body>
</html>

!DOCTYPE

The doctype declaration tells the browser how to properly interpret the HTML document. There are minor variations in older versions of HTML. The current version is HTML5, and it’s doctype declaration is:

<!DOCTYPE html>

<html>

The root element of the document is the <html> element.

It’s good practice to declare the language for the document using the lang attribute, in the <html> element. This allows search engines to properly categorize the page, and screen readers to properly pronouce the words in the document.

<html lang="en">
  ...
</html>

The <head> element will contain information about the document that don’t appear within the document, and links to additional resources required by the document.

<head>
  ...
</head>

<title>

The <title> element goes into the <head> element and contains the page title, which will appear in the page tab.

<title></title>

<body>

The <body> element contains all of the elements that will apear in the document.

<body>
  ...
</body>

The resulting HTML file would look like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    ...
  </head>
  <body>
    ...
  </body>
</html>