The head Tag

 <  Day Day Up  >  


The <head> Tag

The information in the head of an HTML document is very important because it is used to describe or augment the content of the document. The head of an HTML document is like the front matter or cover page of a document. In many cases, the information contained within the <head> tag is information about the information of the page, which generally is referred to as meta-information . This is a very important and often overlooked aspect of HTML documents. Search engines use meta-information to index Web pages. Aside from meta-information, the head element can include author contact information, scripts, style sheets, comments ”and, most importantly, a page title.

The <title> Tag

The most important head element is the title element, which most browsers display in a title bar at the top of the browser window. The document title is actually the only tag required under traditional HTML specifications and should occur as the first element within the head element. XHTML continues the idea of <title> being first in the <head> , but of course does not allow for the optional use of important structural tags such as <html> , <head> , or <body> . Regardless of specification variations, the <title> tag must be used in every HTML document as it gives an HTML document a title by which it is known to browsers and indexing robots. Browsers display the document title while the document is being viewed , and might also use the title in bookmark lists.

Note  

Most browsers attempt to deduce a title for a document that is missing the title element. The browser often uses the URL of the document being viewed, which might indicate nothing about the document's content. However, even this behavior isn't guaranteed . For example, Classic WebTV listed a document without a title as simply "untitled document."

A document title might contain standard text as well as character entities (for example, &copy; ), which are discussed later in the chapter. However, HTML markup isn't permitted in the <title> tag and doesn't produce the expected result. So, according to the rules of the title element,

  <title><strong>  Home Page  </strong></title>  

is not valid, whereas

  <title>  The Demo Company Story  &copy;  2003  </title>  

is. However, a well- formed title is not necessarily a meaningful title. Remember that a user sees a title in his or her bookmark list if the page is bookmarked. Search engines that index the Web often place special meaning on the contents of the title element when determining what a page is about. Because of this, a title should indicate the contents of a page without ambiguity. Titles such as "My Page" or "Home Page" don't make much sense; "John Smith's Home Page" and "Demo Company, Inc." do. A well-formed title actually can add navigational value to a site by showing an implicit hierarchy among a group of pages. Although "Trainer Robot Datasheet" seems to be a reasonable title, "Demo Company: Products: Trainer Robot Datasheet" is a better title. It not only indicates the company the product is related to, but implies a hierarchy in the site.

Note  

In the early days of the Web, using characters such as a colon (:), slash (/), or backslash (\) in titles was a problem. An operating system might have a problem with these titles if the document was saved to the local system. For example, the colon isn't allowed within Macintosh filenames, and slashes generally aren't allowed within filenames because they indicate directories. Although this appears to be a problem, most browsers remove the suspect characters and reduce them to spaces during the Save process. To be on the safe side, dashes can be used to delimit sections in the title.

While titles should be descriptive, they should also be concise . Authors should limit title length to a reasonable number of characters. Netscape and Internet Explorer display around 20 “30 characters of a title in their bookmark lists. One way to limit the length of titles is to remove words such as "a," "an," and "the," which provide little extra value.

Note  

Some browsers are very sensitive to the misuse of the <title> tag. Even before the rise of XHTML, according to the HTML 3.2 and 4.0 specifications, the title element is mandatory, while the html , head, and body elements are not. In some versions of Navigator, omitting the </title> tag causes a document to not display. So, if you get a bunch of junk on your screen (see Figure 1-4), check the <title> tag right away.

click to expand
Figure 1-4: Problem with <title> under Netscape Navigator

According to the HTML and XHTML specifications, only one title element should appear in every document. The title should appear in the head of the document. Under extremely old browser versions, multiple <title> tags often were used within documents to create an animated title. This was a bug and modern browsers don't support this capability; thus, it shouldn't be used.

Other head Elements

In addition to the title element under the HTML 4.01 and XHTML 1.0 transitional DTDs, the elements allowed within the head element include base , isindex , link , meta , object , script , and style. A brief discussion of the other head elements follows . Complete information is available in the cross-referenced chapters and reference section.

The <base> tag specifies an absolute URL address that is used to provide server and directory information for partially specified URL addresses called relative links used within the document. Links and the use of <base> are discussed in Chapter 4.

The <isindex> tag indicates that the document contains a searchable index. It causes the browser to display a query prompt and a field for entering a query. This element typically was used with simple site searching mechanisms, but is rarely used today, having been mostly replaced by forms. Under the HTML 4.01 and XHTML 1.0 strict definitions, <isindex> is deprecated. The element is discussed solely in Appendix A, as its use is discouraged.

The <link> tag specifies a special relationship between the current document and another document. It can be used in hypertext navigational relationships including prefetching of documents by browsers, which is discussed in Chapter 4. It can also be used to link the current document to a style sheet, which is discussed in Chapter 10. The <link> tag has many interesting possibilities, but unfortunately few of these are implemented even in the most standards-compliant browser.

The <meta> tag uses name /value pairs to provide meta-information about a document. The <meta> element often provides descriptive information targeted by Web search engines. In a very different use, the <meta> tag can define various HTTP request values such as a page refresh or an expiration time. These and other uses are discussed in Chapters 16 and 17, which cover site delivery and site maintenance, respectively.

The <object> tag allows programs and other binary objects to be directly embedded in a Web page. The most popular current approaches use Java applets, plug-ins, or ActiveX controls to embed multimedia elements such as Flash animations, sounds, or movies. The <object> tag is discussed in Chapter 15.

The <script> tag allows programs written in a scripting language to be directly embedded in a Web page. The most popular scripting language in Web documents is JavaScript, which is somewhat standardized in the form of ECMAScript, although few Web practitioners refer to it as that. The script element and associated usage of scripts, often dubbed Dynamic HTML (DHTML) because it allows HTML elements to be modified dynamically, should simply be considered a form of client-side scripting. It is discussed in Chapter 14.

The < style> tag encloses document-wide style specifications relating to fonts, colors, positioning, and other aspects of content presentation. Today, the primary style sheet technology used in Web pages is called Cascading Style Sheets (CSS), which is discussed extensively in Chapters 10 and 11.



 <  Day Day Up  >  


HTML & XHTML
HTML & XHTML: The Complete Reference (Osborne Complete Reference Series)
ISBN: 007222942X
EAN: 2147483647
Year: 2003
Pages: 252
Authors: Thomas Powell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net