HTML: The Definitive Guide

Previous Chapter 2
HTML Quick Start
Next
 

2.7 Hyperlinks

While text may be the meat and bones of an HTML document, its heart is hypertext. Hypertext gives users the ability to retrieve and display a different document in your own or someone else's collection simply by a click of the mouse on an associated word or phrase (hyperlink ) in your HTML document. Use these interactive hyperlinks to help readers easily navigate and find information--in your own, or others' collections--of otherwise separate documents in a variety of formats, including multimedia, HTML, and plain ASCII text. Hyperlinks literally bring the wealth of knowledge on the whole Internet to the tip of the mouse pointer.

To include a hyperlink to some other document in your own collection or on a server in Timbuktu, all you need to know is the document's unique address and how to drop an anchor into your HTML document.

URLs

While it is hard to believe, given the millions, perhaps billions, of them out there, every document and resource on the Internet has a unique address known as its uniform resource locator (URL; commonly pronounced "you-are-ell"). A URL is comprised of the document's name preceded by the hierarchy of directory names in which the file is stored (pathname), the Internet domain name of the server that hosts the file, and the software and manner by which the browser and the document's host server communicate to exchange the document (protocol):

protocol://server_domain_name/pathname

Here are some sample URLs:

http://www.kumquat.com/docs/catalog/price_list.html
http:price_list.html
http://www.kumquat.com/
ftp://ftp.netcom.com/pub/

The first example is what's known as an absolute or complete URL. It includes every part of the URL format--protocol, server, and the pathname of the document.

While absolute URLs leave nothing to the imagination, they can lead to big headaches when you move documents to another directory or server. Fortunately, browsers also let you use relative URLs and automatically fill in any missing portions with respective parts from the current document's base URL. The second example is the simplest relative URL of all; it assumes that the price_list.html document is located on the same server and in the same directory as the current document.

Relative URLs are also useful if you don't know a directory or document's name. The third URL example, for instance, points to kumquat.com's web home page.

Although appearances may deceive, the last FTP example URL actually is absolute; it points directly at the contents of the /pub directory.

Anchors

The anchor (<a>) tag is the HTML feature for defining both the source and the destination of a hyperlink.[4] You'll most often see and use the <a> tag with its href attribute to define a source hyperlink. The value of the attribute is the URL of the destination.

[4] The nomenclature here is a bit unfortunate: the "anchor" tag should mark just a destination, not the jumping off point of a hyperlink, too. You "drop anchor"; you don't jump off one. We won't even mention the atrociously confusing terminology the HTML standard uses for the various parts of a hyperlink except to say that someone got things all "bass ackwards."

The contents of the source <a> tag--the words and/or images between it and its </a> end tag--is the portion of the HTML document that is specially activated in the browser display and that users select to take a hyperlink. These anchor contents usually look different from the surrounding content (text in a different color or underlined, images with specially colored borders), and the mouse pointer icon changes when passed over them. The <a> tag contents, therefore, should be text or an image (icons are great) that explicitly or intuitively tells users where the hyperlink will take them. [the section called "The <a> Tag"]

For instance, the browser will specially display and change the mouse pointer when it passes over the "Kumquat Archive" text in the following example:

For more information on kumquats, visit our 
<a href="http://www.kumquat.com/archive.html">
Kumquat Archive</a>

If the user clicks the mouse button on that text, the browser automatically retrieves from the server www.kumquat.com a web (http:) page named archive.html, and then displays it for the user.

Hyperlink Names and Navigation

Pointing to another document in some collection somewhere on the other side of the world is not only cool, but it also supports your own HTML documents. Yet the hyperlinks' chief duty is to help users navigate your collection in their search for valuable information. Hence, the concept of the home page and supporting HTML documents has arisen.

None of your HTML documents should run on and on. First, there's the performance issue: the value of your work suffers, no matter how rich it is, if the document takes forever to download, and if once retrieved, users must endlessly scroll up and down through the display to find a particular section.

Rather, design your work as a collection of several compact and succinct pages, like chapters in a book, each focused to a particular topic for quick selection and browsing by the user. Then use hyperlinks to organize that collection.

For instance, use your home page--the leading document of the collection--as a master index full of brief descriptions and respective hyperlinks to the rest of your collection.

You should also use the special attribute of the <a> tag called name. Anchors with the name attribute serve as internal hyperlink targets in your HTML documents. Normally, the browser displays a freshly downloaded document at the beginning. Name anchors let you begin the display at the section of interest further down. Simply include them anywhere that they make sense as a hyperlink target. They do not change the appearance of enclosed or surrounding content.

Thereafter, you may append the name, after a separating pound sign (#), as a suffix in the URL of a hyperlink that references that specific place in your document. For instance, to reference a specific topic in an archive, such as "Kumquat Stew Recipes" in our example Kumquat Archive, you mark that section with a name anchor:

... preceding content... 
<a name="Stews"> 
<h3>Kumquat Stew Recipes</h3>
</a>

In the same or another document, you prepare a source hyperlink that points directly to those recipes by including the section's anchor name as a suffix to the document's URL, separated by a pound sign:

For more information on kumquats, visit our 
<a href="http://www.kumquat.com/archive.html">
  Kumquat Archive</a>, 
and perhaps try one or two of our
<a href="http://www.kumquat.com/archive.html#Stews"> 
  Kumquat Stew Recipes</a>.

If selected by the user, the latter hyperlink causes the browser to download the archive.html document and start the display at our "Stews" anchor.

Anchors Beyond HTML

HTML hyperlinks are not limited to other HTML documents. Anchors let you point to nearly any type of document available over the Internet, including other Internet services.

However, "let" and "enable" are two different things. Browsers can manage the various Internet services, like FTP and Gopher, so that users can download non-HTML documents. They don't yet fully or gracefully handle multimedia.

Today, there are few standards for the many types and formats of multimedia. Computer systems connected to the Web vary wildly in their abilities to display those sound and video formats. Except for some graphics images, standard HTML gives you no specific provision for display of multimedia documents except the ability to reference one in an anchor. The browser, which retrieves the multimedia document, must activate a special helper application, download and execute an associated applet, or have a plugin accessory installed to decode and display it for the user.

Although HTML and most web browsers currently avoid the confusion by sidestepping it, that doesn't mean you can't or shouldn't exploit multimedia in your HTML documents: just be aware of the limitations.


Previous Home Next
HTML and Text Book Index Images Are Special

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
Hosted by uCoz