Basic HTML documents have two elements, <head> and <body>. The <head> portion of this type of document can define the document and contain information about it that may not be displayed in the browser. Search engines often use the contents of the markup in the <head>. Also contained in the <head> element are references to other documents and objects that may be used in the document but not contained in the <body>. The following shows the basic elements of the <head> element:
<head> <title></title> <meta /> <link></link> <base /> </head>
The <title> is the page header in the browser window. This element is required in all HTML documents. This markup has a start tag and end tag and is never empty. The <title> in the <head> element is different from "title" attribute, often used within other elements.
<title>This is my document!</title>
The <meta> element has many attributes and provides information about the document. The name attribute is used to specify values such as keywords, author, copyright, and date. Search engines that index your web page may use the name attribute. Other values for the name attribute are: author-corporate, author-email, author-personal, description, generator, htdig-email, htdig-email-subject, htdig-keywords, htdig-noindex, htdig-notification-date, publisher-email, and robots. Instead of name, the http-equiv attribute is used to send a message to the browser with values such as expires, refresh, and Content-Type. Other http-equiv values are: cache-control, content-language, content-script-type, content-style-type, PICS-Label, pragma, vary, and set-cookie. The attribute content is required and used with the name or http-equiv attributes. The <meta> element is always empty, as seen in Listing 6.1, so include the space and slash characters ( /) at the end of the element to make it XHTML compliant.
Listing 6.1: META element examples
<meta name="keywords" content="HTML, XML, XHTML" /> <meta name="author" content="Beverly Voth" /> <meta name="copyright" content="2001" /> <meta name="date" content="2002-01-01" /> <!-- to force the browser to reload a page --> <meta http-equiv="expires" content="" /> <!-- to redirect the browser to another page --> <!-- the content specifies the seconds to wait before going to the URL --> <meta http-equiv="refresh" content="5;URL=theNextPage.html" /> <meta http-equiv="Content-Type" content="" />
The document "HTML 4.01 Specification W3C Recommendation 24 December 1999," http://www.w3.org/TR/1999/REC-html401-19991224, states in section 4.3 that the Content-Type for an HTML document is text/html. It is strongly recommended that charset is included.
<meta http-equiv="Content-Type" content="text/html; charset=Latin-1" />
STYLE and SCRIPT in external documents can also be replaced with the single element LINK. This element is always empty and always placed within the <head> element. The attributes for the <link> are described in Table 6.1. An advantage of using <link> is the ability to include more than stylesheets and external script documents.
The relationship from this page to others. The values of rel can be Alternate, Stylesheet, Start, Next, Prev, Contents, Index, Glossary, Copyright, Chapter, Section, Subsection, Appendix, Help, and Bookmark. An example of <link> attributes is shown below:
<head> <title>Page 2</title> <link rel="Index" href="index.html" /> <link rel="Prev" href="page1.html" /> <link rel="Next" href="page3.html" /> </head>
The location of the referenced document.
Other attributes for the <link> element are rev (reversed link to this document), id, class, lang (language), dir (direction of language), title, style, src (location of stylesheet document), onfocus, onblur, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmouseout, onkeypress, onkeydown, onkeyup, target (used with href if using windows and frames), tabindex (tab order), accesskey, media (such as screen, TV, print, Braille), and charset. You can read more about some of these attributes as they apply to other elements listed here.
The final element in the <head> element is the <base> element. <base> is a way to specify the location of the particular document containing the BASE element. This element is also used by any internal references by the current document to external sources. Rather than include a full path to each reference (absolute path), you can include the relative path to the <base> path of the document. This resolves possible confusion with these relative resources. The sample code for this element is shown below. <base> should be listed in the <head> element and above any relative paths, including any that might be in <style>, <script>, <meta>, and <link>.
<head> <base href="http://mydomain.com/anotherFolder/thisDocument.html" target="_top" /> <link rel="Next" href="page3.html" /> </head>