Every HTML document consists of two basic parts: the "head" and the "body." The head starts with the <head> tag and ends with the </head>, for the body the <body> tag is used in a similar manner. Both the head and the body must be enclosed in <html>....</html>
Thus, a typical HTML document has the following basic structure:
To sum it up, enclosed between the
<html>...</html> tags there are two basic parts -- the document head, and the document body. The head is mostly concerned with providing information about the document itself, while the body contains the information that people see in their browsers.
Note that for your document to be standards compliant, you will need to specify the correct Document Type Declaration (also known as Doctype), and possibly add a few other features. Nevertheless, the beginning chapters of the Primer will omit these specifics, because they do not interfere with the functionality of the provided examples and can always be added later.
One last thing: the above example displays an important feature of HTML tags, the so called "nesting." If you open tag A and then open tag B, you must close tag B before you close tag A.
The title tag usually contains the site's name and short description, which are displayed in the browser's title bar and tabs.
The link element defines an external resource -- in practice, you will use this to link to an external CSS file, which contains the style rules for all content in the body:
<link rel="stylesheet" type="text/css" href="my_style.css" />
By specifying a base URL, you point all relative links with the document body to that base URL.
For example, if set
<base href="http://example.com" /> and then create the link
<a href="document.html" />, it will actually point to
http://example.com/document.html. When no base URL is specified, it defaults to the home directory of the HTML file.
Meta tags provide information about the document -- its purpose, keywords, author, etc. Properly written and placed meta tags are important for search engine visibility. Here are some key examples:
Keywords for search engines:
<meta name="keywords" content="HTML, web design" />
Web page description:
<meta name="description" content="A page about HTML and web design" />
The above meta tags are normally included in every web page, but they can alsocontain optional information:
<meta name="author" content="John Smith" />
The body of your HTML document contains all content that is displayed in a browser: text, images, lists, tables, and more. Because the essence of HTML for beginners is learning how to place content in the document, the several next chapters are dedicated to practical examples of how to work with body elements.