Teach Yourself Web Publishing with HTML 4 in 21 Days
Chapter 5: All About Links
This chapter introduces anchor tags, which are used to create
hypertext links. The objectives important to this chapter are:
- the anchor tag
- relative and absolute paths to files
- structure tags
- using URLs to link to documents
- links to anchor points
- parts and types of URLs
A link tells the browser to jump somewhere other than the text
it is currently displaying. You need two things to make that work: a place
to jump to and a place to jump from. To create the place to jump from
we use anchor tags. They are called anchors because they also are
used to create spots to jump to: anchor points.
Anchor tags are special because they can use several optional values
inside the angle brackets. For example, this tag:
uses the NAME value to create an anchor point in the document that it
is typed in. The anchor point is called "Chapt4". Note that no visible
text is involved with this anchor point, so it is not obvious to the viewer.
This tag creates a jump point:
<a HREF="review1.htm">Review Page</a>
When the reader sees this in the browser, only the plain text "Review
Page" is visible. The fact that the anchor uses the HREF option makes
this a hypertext jump point that can be clicked to jump to the page specified.
When specifying a page to jump to, it is necessary to know where that
page is. It is simplest to jump to a page in the same directory as the
page you are jumping from. This was done in the last example, specifying
only the name of page to go to. When doing this, you may use either relative
or absolute page references. The difference is that a relative
reference shows the DOS or UNIX path to the next document, based on where
you are now in the directory structure, while the absolute reference shows
the path to the file starting at the root of the drive containing it.
Neither sort of reference is quite enough when jumping to a page not
on your own site. That is what the web is all about, after all, jumping
anywhere. So, to go to a page at a different site, you include the full
URL to that page, protocol and all. This is an example:
<A HREF="http://stevevincent.info/index.html">Steve Vincent's
The HREF value here is the entire code necessary to send the browser
to my home page, including the HTTP protocol. It specifies the server
name, as well, and the directory to go to, and finally the page to read.
In all of these examples, the HTTP protocol is being used, but this time
I specified the name of a server on a network as well, which enables the
browser to send an IP based request across the Internet to the correct
To link your document to a particular spot in a document somewhere,
the place you want to link to must be given a name, like in the first
example above. The the link to get there needs to have an HREF value,
as usual, with the addition of a pound sign and the name given to the
spot you want to link to. Example:
This link would take us to the anchor named "part2" in the document called
"review1.htm" which must exist in the same directory as the current file,
since this is a relative link with no directory information included.
If you want to link to a named anchor in the same file you are in, just
use the part from the pound sign on as the value for HREF. The browser
then assumes that the link exists in the same file. If the browser does
not find a named position that it has been told to jump to, then it will
jump to the beginning of the document named in the HREF value.
URLs can use other protocols than HTTP. Commonly used protocols are:
- ftp - either anonymous, or non-anonymous, which means that
you have to supply a user ID and a password.
- file - this is the protocol you will see used when you open
a file from your hard drive (or floppy)
- gopher - used to read files stored in Gopher search format
- mailto - used to send e-mail through your browser; only works
if your browser is set up for e-mail