Learning HTML 3.2 by Examples, section 5 Descriptions of HTML 3.2 tags:

A - anchors, hyperlinks, etc


To set up hyperlinks and "anchors" for them, i.e.

In principle, the A element can also be used for some other purposes which are currently of little practical value.

Typical rendering

An A element of the form <A HREF="target">anchor text</A> is displayed so that anchor text is presented in a distinguished manner (e.g. underlined or highlighted). The reader might even tell his browser not to present links in any distinguished manner, especially when the document is printed on paper. (On paper output, links might also be presented using footnotes.)

There are no automatic newlines or similar phenomena involved in presenting the anchor text; this means that the anchor text can be part of normal text flow in the document.

The user may select the anchor text (in a browser-dependent manner, using e.g. arrow keys for moving the cursor and enter key for selecting, or the mouse for moving the cursor and a mouse button click for selecting). In that case the document or location in a document as specified by the target, if existent and accessible, will be fetched and presented to the user. A browser may allow the user to select whether the document is to be displayed in the same or in another window on the screen.

The visual look of anchor texts is settable by user options in many browsers. It can depend on whether the target has been visited by the user or not. It is also affected by eventual LINK and VLINK attributes in a BODY element. When a document is printed, an anchor text might appear, depending on the browser and its settings, e.g. as normal text or underlined text, or footnotes (indicating the target URL) might be attached to it.

If anchor text is (or contains) an IMG element, a browser generally indicates the image as a link by drawing a colored (typically blue) border around the image. The width (and existence) of such a border can be controlled by the BORDER attribute of the IMG element. (Notice that if you suppress the border by using BORDER=0, you should separately indicate the image as a link, since otherwise the user won't know it's a link.)

Other A elements than those containing an HREF attribute have no effect on the rendering of a document. (Exception: a few browsers present the text within an A element with a NAME attribute in some highlighted manner.)

Basic syntax

<A HREF="target">anchor text</A>


<A NAME="name"></A>

Possible attributes

attribute name possible values meaning notes
NAME string a name for a link end must be unique within the document; case sensitive
HREF URL network address for the linked resource could be another HTML document, a PDF file, an image etc
REL string the forward relationship also known as the "link type"; see notes on REL and REV values in the general description of links in principle, could be used by browsers and other software in several ways, e.g. to determine to how to deal with the linked resource when printing out a collection of linked resources
REV string the reverse relationship: a link from document A to document B with REV=relation expresses the same relationship as a link from B to A with REL=relation.
TITLE string a title for the linked resource advisory; see remarks below

The value of a TITLE attribute might be used e.g.

(Not all browsers actually use the attribute in manners like those described above)

Allowed context

Text container, i.e. any element that may contain text elements, except an A element. This includes most HTML elements.


Text elements, except A elements. Notice that this includes IMG (you can have an image as the "anchor text") but excludes headings (you can have A elements within headings but not vice versa).


Example A.html:

<P>A hyperlink referring to a document in the same directory
as the current one:
<A HREF="ADDRESS.html">Examples of using ADDRESS tag</A>.
<P>A hyperlink referring to a document elsewhere:
<A HREF="http://www.hut.fi/english.html">HUT</A>.
<p>A hyperlink referring to a label in the same document:
<A HREF="#final">final example</A>.
<P>A hyperlink referring to a label in another document:
<A HREF="http://www.ncsa.uiuc.edu/General/Internet/WWW/HTMLPrimerP2.html#UR">
URL info in HTML Primer</A>
<P>A link to an image:
<A HREF="../perhe.jpg"
   TITLE="Yucca's family picture, by Minna">a family picture</A>.
<P><A NAME="final">Finally, this is just text to which you can
refer with a hyperlink.</A>


See the general discussion of links, which contains additional examples as well as notes on normal links links to audio and video resources, links to binary and plain text files, and links to other non-HTML resources (such as mailto: links).

Don't use an anchor text like Click here. They look stupid e.g. in a paper copy of a document. Warren Steel says in Hints for Web Authors:

You don't need to say "Click here for information on our graduate programs;" just insert the link into what you were saying: "Our excellent graduate programs ..." Links to large files or unusual formats should be so marked, perhaps in a parenthetical note. "Our stirring fight song (400k .au) ..."

It is a rather common error to omit quotes or the closing quote in an HREF attribute. Some browsers are permissive, others may get very confused, so that the link may not work at all.

You cannot nest A elements, but you can write a dual-purpose A element which has both an HREF and a NAME attribute, e.g. <A NAME="foo" HREF="#bar">zap</A>

An A element with NAME attribute specifies a location which can be referred to by URLs with fragment identifiers. For example, <A NAME="foo"> specifies a target which can be referred to by <A HREF="#foo"> in the same document. Notice that other authors cannot refer to specific locations in your documents unless you include suitable anchors. Thus, it is often advisable to use an A NAME element at least for (technically, within) the major heading elements.

It is not obvious what exactly is the entity named in A NAME element. The most natural interpretation seems to be that it is a part of the document, namely the part between the start and end tags. However, notice that only text elements are allowed within the contents and that most browsers seem to interpret things so that an A NAME element just names a location (a point) in the document, namely the location of the start tag, leaving the position of the end tag meaningless. (However, an end tag </A> is obligatory!)

It is syntactically legal to have an A element with empty content, such as <A NAME="foo"></A>, but this has been observed to confuse some browsers. The simple solution is include a few words from the text into the A NAME element, e.g.

<P><A NAME="summary">To summarize</A>, it is legal but not advisable
to have an A element with empty content.</P>               

If an A element contains an IMG element with the ISMAP attribute, they constitute a server-side image map.

Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.