Standing Head, Title, and Body of HTML Files

By Nikhil Abraham

HTML files are structured in a specific way so browsers can correctly interpret the file’s information. Every HTML file has the same five elements: four whose opening and closing tags appear once and only once, and one that appears once and doesn’t need a closing tag. These are as follows:

  • !DOCTYPE html must appear first in your HTML file, and it appears only once. This tag lets browsers know which version of HTML you are using. In this case, it’s the latest version, HTML5. No closing tag is necessary for this element.

    For HTML4 websites, the first line in the HTML file would read <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

  • html represents the root or beginning of an HTML document. The <html> tag is followed by first an opening and closing <head> tag, and then an opening and closing <body> tag.

  • head contains other elements, which specify general information about the page, including the title.

  • title defines the title in the browser’s title bar or page tab. Search engines like Google use title to rank websites in search results.

  • body contains the main content of an HTML document. Text, images, and other content listed between the opening and closing body tag is displayed by the browser.

Here is an example of a properly structured HTML file with these five tags:

image0.jpg

<!DOCTYPE html>
<html>
<head>
   <title>Favorite Movie Quotes</title>
</head>
<body>
   <h1>"I'm going to make him an offer he can't refuse"</h1>
   <h1>"Houston, we have a problem"</h1>
   <h1>"May the Force be with you"</h1>
   <h1>"You talking to me?"</h1>
</body>
</html>

Using spaces to indent and separate your tags is highly recommended. It helps you and others read and understand your code. These spaces are only for you and any other human that reads the code, however. Your browser won’t care. As far as your browser is concerned, you could run all your tags together on one line. (Don’t do this, though. The next person that reads your code will be most unhappy.) HTML does recognize and display the first whitespace character in text between opening and closing HTML tags.

The example had many h1 tags but only one opening and closing html, head, title, and body tag.