Tutorials Bugs Masterclass Free stuff Test pages Proposals

Basic concepts

Advanced concepts

RichInStyle.com HTML 4 guide - Links

Contents

Links

The A element

Other attributes of the A element

URIs

Absolute URIs

Relative URIs

Linking to a particular part of a document

Base URIs

Links

The world wide web would be nowhere without links. Without them, there would be no way to get from one page to another without typing in the address by hand.

The A element

The A (anchor) element is used to make links from one document to another. In addition, it is used to create targets for other links to link to. To make a link you enclose the text you want to be marked as a link in an A element:

The <A href="next.html">next section</A>

That example might be rendered thus:

The next section.

As you can see, there are essentially two parts to an A element - its content, enclosed within the A element; and the address to which it is linking, specified by href.

Other attributes of the A element

In addition to specifying the hypertext reference of the anchor, the following attributes may be used:

  1. title - this specifies a title for the link. Titles are used to provide a tooltip for the link when the mouse passes over them. It is recommended that you give all anchors a title because it makes your pages look more professional. For example, <A href="next.html" title="The next section"> would result (in most browsers) in a tooltip saying 'The next section' when the mouse passes over.

URIs

Absolute URIs

Absolute URIs specify the location of links in a way that is absolute - it is not dependent on the location of the linking document - in the same way that 'c:\documents\mydoc.doc' is meaningful from anywhere on your hard disk, so too http://www.richinstyle.com is meaningful regardless of the location of a web page.

To use absolute URIs, you must specify the type of mechanism that is used to link to the resource. For example, <A href="http://www.richinstyle.com"> or ftp://www.foo.com.

In addition to these, you may also specify a link to an e-mail address. For example, <A href="mailto: foo@foo.com">.

Relative URIs

Relative URIs specify the location of linked resources relative to the location of the linking document. For example, if a document is http://www.richinstyle.com/guides/links4.html, then <A href="html4.html"> is interpreted as relative to the directory that links4.html is in. Thus that A element would result in http://www.richinstyle.com/guides/html4.html.

In addition, you may specify a directory - <A href="/copyright.html"> from http://www.richinstyle.com/guides/html4.html means http://www.richinstyle.com/copyright.html, since the / means relative to the root directory.

<A href="./html4.html"> from http://www.richinstyle.com/guides means http://www.richinstyle.com/guides/html4.html, since the '.' means the current directory.

<A href="../copyright.html"> from http://www.richinstyle.com/guides means http://www.richinstyle.com/copyight.html, since the '..' means up one directory.

Finally, <IMG src="guides/html.gif"> from http://www.richinstyle.com means http://www.richinstyle.com/guides/html.gif.

Linking to a particular part of a document

If you want to link to a particular part of a document, for example to make cross-references within a document, it is essential to be able to refer to a particular party of the document.

This is done using the A element with the name attribute. For example:

<H1>
<A name="x"></A>
A heading
</H1>

This could then be referred to by <A href="#x">, or <A href="http://www.richinstyle.com/document.html#x"> (i.e., you add the '#' sign and the name of the link to the URI).

Note that two identical anchor names cannot appear in the same document, and even though names are case-sensitive, they cannot be identical but for case either.

Base URIs

Base URIs are specified using the <BASE> element. Base URIs allow you to reduce the amount of typing that you have to do - instead of:

<A href="http://www.foo.com/foo/foostuff/foo.html"></A>
<IMG src="http://www.foo.com/foo/foostuff/foo.html">
etc.

you would have:

<HEAD>
<BASE href="http://www.foo.com/foo/foostuff/">
</HEAD>
<BODY>
<A href="foo.html"><IMG src="foo.gif"></A>
</BODY>

Thus you simply put the reference of the base URI from which all others are interpreted and you can reduce typing.

That's the end of this part of the HTML guide. The next section considers essential concepts, things such as how to refer to characters like < so I suggest you click here to continue.