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. In its simplest incarnation, it looks like this:

I'm <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>

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

Absolute URLs

An absolute URL is made up of the following components: a protocol identifier, a host name (the name of the server machine), the pathname (if there is one), and the specific file name. When you are linking to documents on other servers, you need to use an absolute URL. The following is an example of a link with an absolute URL:

<A HREF="http://www.littlechair.com/web/index.html">...</A>

Here the protocol is identified as http (the standard protocol of the Web), the host is www.littlechair.com and web/index.html is the pathname leading to the particular file.

Relative URLs

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

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

www.littlechair.com/web/samples/jcc.html ...

Get Web Design in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.