home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomeWeb Design in a NutshellSearch this book

11.2. Simple Hypertext Links

The anchor (<a>) tag is used to identify a string of text or an image that serves as a hypertext link to another document. Linking to a string of text looks like this:

I am <A HREF="link.html">linking</A> to you!

To make an image a link, enclose the image tag within the anchor tags as follows:

<A HREF="link.html"><IMG SRC="pixie.gif"></A>

Most graphical browsers display linked text underlined and in blue by default, but this behavior can be altered. Linked graphics appear with a blue outline (unless you turn the outline off in the <img> tag by setting the border attribute to zero).

The URL is the pathname of the document you want to link to. URLs can be absolute or relative.

11.2.2. Relative URLs

A relative URL provides a pointer to another document relative to the location of the current document. The syntax is based on pathname structures in the Unix operating system, which are discussed in Chapter 4, "A Beginner's Guide to the Server". When you are pointing to another document within your own site (on the same server), it is common to use relative URLs.

For example, if I am currently in resume.html (identified here by its full pathname):


and I want to put a link on that page to bio.html, which is in the same directory:


I could use a relative URL within the link as follows:

<A HREF="bio.html">...</A>

Using the same example, to link to the file index.html in a higher level directory (web), I could use the relative pathname to that file as shown:

<A HREF="../index.html">

This relative URL is the equivalent to the absolute URL http://www.littlechair.com/web/index.html.

By default, a relative URL is based on the current document. You can change that by placing the <base> element in the document header (<head>) to state explicitly the base URL for all relative pathnames in the document. The <base> tag can only appear in the <head> of the document, and it should appear before any other element with an external reference. The browser uses the specified base URL (not the current document's URL) to resolve relative URLs.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.