9.4. Using <meta> Tags
The <meta> tag has a wide variety of applications, but is primarily used to include information about a document, such as the creation date, author, or copyright information. The data included in a <meta> tag is useful for servers, web browsers, and search engines but is invisible to the reader. It must always be placed within the <head> of the document.
A document may have any number of <meta> tags. There are two types of <meta> tags, using either the name or http-equiv attribute. In each case, the content attribute is necessary to provide a value (or values) for the named information or function. The examples below show basic <meta> tag syntax. In the following sections, we will look at each type of meta tag and its uses.
<META HTTP-EQUIV="name" CONTENT="content"> <META NAME="name" CONTENT="content">
9.4.1. The http - equiv Attribute
Information provided by an http-equiv attribute is processed as though it had come from an HTTP response header. HTTP headers contain information the server passes to the browser just before it sends the HTML document. It contains MIME type information and other values that affect the action of the browser. Therefore, the http-equiv attribute provides information that will, depending on the tag description, affect the way the browser handles your document.
There are a large number of predefined http-equiv types available. This section will look at just a few of the most useful. For a complete listing, see the Dictionary of HTML META Tags at http://vancouver-webpages.com/META/.
126.96.36.199. Meta tags for client-pull
Client-pull refers to the ability of the browser (the client) to automatically request (pull) a new document from the server. The effect for the user is that the page displays, and after a period of time, automatically refreshes with new information or is replaced by an entirely new page. This technique can be used to automatically redirect readers to a new URL (for instance, if an old URL has been retired). Be aware, however, that the W3C strongly discourages the use of this method for automatic forwarding in favor of server-side redirects.
If you string documents with client-pull instructions and set very short time intervals, you can create a sort of slide show effect. Client-pull uses the refresh attribute value, first introduced by Netscape. It tells the browser to wait a specified number of seconds (indicated by an integer in the content attribute) and then load a new page. If no page is specified, the browser just reloads the current page. The following example instructs the browser to reload the page after 15 seconds (we can assume there's something fancy happening on the server side that puts updated information in the HTML document):
<META HTTP-EQUIV="refresh" CONTENT="15">
<META HTTP-EQUIV="refresh" CONTENT="1; URL=http://doc2.html">
Note that there is only a single set of quotation marks around the value for content. Although URLs usually require their own quotation marks, these are omitted within the context of the content attribute.
To create a slide-show effect, add a meta refresh tag in the <head> of each document that points to the next HTML document in the sequence. You can set the time interval to as many seconds as you like; setting it to 0 will trigger the next page as soon as the current page has downloaded. Bear in mind, however, that the actual amount of time the page takes to refresh is dependent on complex factors of file size, server speed, and general web traffic.
In the following example, three files are coded to loop endlessly at five-second intervals.
Document 1.html contains:
<META HTTP-EQUIV="refresh" CONTENT="5; URL=2.html">
Document 2.html contains:
<META HTTP-EQUIV="refresh" CONTENT="5; URL=3.html">
Document 3.html contains a tag which points back to 1.html :
<META HTTP-EQUIV="refresh" CONTENT="5; URL=1.html">
188.8.131.52. Other uses
Here are some other uses of the http-equiv attribute:
9.4.2. Inserting Meta-Information with the name Attribute
The name attribute is used to insert hidden information about the document that does not correspond to HTTP headers. For example:
<META NAME="author" CONTENT="Jennifer Niederst"> <META NAME="copyright" CONTENT="2001, O'Reilly & Associates">
You can make up your own <meta> names or use one of the names put forth by search engine and browser companies for standardized use. A few of the accepted and more useful <meta> names are discussed in the following sections.
184.108.40.206. Meta tags for search engines
The popular search engines Infoseek and AltaVista introduced several <meta> names that aid their search engines in finding pages. Note that not all search engines use meta data, but adding them to your document won't hurt. There is a blurry distinction between name and http-equiv in this case, so most of these meta names also work as http-equiv definitions.
220.127.116.11. Other uses
Other uses of the name attribute include the following:
Copyright © 2002 O'Reilly & Associates. All rights reserved.