HTML Anchor (Hyperlinks)

The anchor element is used to create hyperlinks. Be sure to provide the correct URL. Also notice that the user must be provided with a hyperlink–something to click on! This can be text or an image.

<a href="http://www.utm.edu">UTMartin</a>

UTMartin

Two Types of Addresses

The example provided above uses an absolute address; in other words, the full path to the file is provided. However, if the hyperlink is referring to a file on the same server, a relative address might be more appropriate. A relative address simply lists the file name; sometimes the folder may be specified.

Note that this demonstration does not actually work.

<a href="DrFoltz.html">Dr. Foltz</a>

Dr. Foltz

Block Anchor

In HTML5, an entire block element such as a paragraph can be used as an anchor.

E-Mail Hyperlinks

A hyperlink can open the default email software on a computer.

Note that this demonstration does not actually work.

<a href="mailto:fake@email.com>Email a fake address</a>

Email a fake address

Telephone Hyperlinks

Hyperlinks can also place telephone calls (assuming the page is being viewed on a telephone).

Note that this demonstration does not actually work.

<a href="tel:1234567890">Call me</a>

Call me

Target Attribute

The anchor statement also accepts the target attribute. The target attribute accepts values of _blank, _self, _parent, and _top. These control where the page opens; _self is the default and opens in the same window. _blank opens a new window or tab, while _parent opens in the parent window. _top causes the hyperlink to open in the main body of the window.

Bookmarks

The anchor statement, combined with the ID attribute, can be used to create bookmarks, or hyperlinks within a document. These are useful for creating a table of contents or a "return to top" link.

In the body of the document, simply create an element with an ID. For example,

<h1 id="ch1">

Next, create a hyperlink to that ID.

<a href="#ch1">Chapter One</a>

Of course the hyperlink is typically placed at the top of the document.