Advanced HTML

HTML Documents

Key points
  • Complete HTML documents have a head, a title, and a body. The <html> tag is always first.
  • Web browsers use a document's title to identify the page.
  • Search engines use metadata to find and index web pages.

A Full HTML Document

The very first example in this manual used the <html> and <body> tags. Now we return to see what it takes to really makes an HTML document. Web browsers will usually display any file that ends with .htm (or some prefer .html) as a web page, even if it only contains text. A correct HTML document, however, contains at a minimum:

Click to view Live Example

<html>
	<head>
		<title>This text appears in the browser's title bar and history</title>
	</head>
	<body>
	</body>
</html>
A minimal HTML document

Note that the html tag is the first and only element at the root level of the document: all of the other elements are children of html. Then there are two "sections" to a document: the head and the body. The <head> tag is used to give the browser more information about the document such as title, author, and description. The next section shows how styles can also exist in the head when they are not specific to a particular element. The <body> tag contains all of the visible content for the document.

HTML Metadata

The most important tag that appears in the head of a document is the <title> tag. It contains the text used by the browser to identify which page the user is currently viewing. It is important to add a title tag to every HTML document, usually before beginning on the body of the document. Besides the title, HTML document heads can contain information called metadata, which browsers may choose to show in a separate dialog. One of the most common metadata for HTML documents is author information. Metadata is added to a page using the <meta> tag:

<head>
	<meta name="author" content="Paul Spangler" />
</head>
Using the meta tag to show the author of a page

The name attribute tells the browser what the metadata means, while the content attribute is the value for that metadata. In this case, the author of the page is Paul Spangler. Other useful metadata includes description and keywords, which are used by search engines to determine when to show your web page as a in search results.

The head of an HTML document can also include styles common to the entire document (see the next section), as well as scripting code called JavaScript that is used to create interactive web pages.