a (HTML element)
| Depr. | Empty | Version |
|---|---|---|
| No | No | HTML 2 |
| IE5.5+ | FF1+ | SA1.3+ | OP9.2+ | CH2+ |
|---|---|---|---|---|
| Full | Full | Full | Full | Full |
Syntax
Description
At one
character long, this is one of the smallest elements, but
a is the lifeblood of the World Wide Web. It’s this
element that links the billions of web pages together, allowing you to
surf from page to page almost endlessly. To say that it’s the most
important element of all those presented here would not be an
exaggeration.
The a element is
usually referred to as a link (not to be confused with the link element, which has a different purpose),
or even a hyperlink—although people who refer to hyperlinks probably also
talk about “the information superhighway” and think that the film
Tron is cutting-edge! This element’s purpose is simple: it
wraps around text, or an image, or both, and refers to another web page,
or another section on the same web page; the user can click on the
contained text or image, or tab to it and activate with the keyboard’s
Enter key. The enclosed text will be underlined by default in all
browsers, which signifies that it’s a clickable link. It’s for this reason
that you shouldn’t use the u
element; underlines are best left on links, and links alone. In most
browsers, an image that’s contained inside an a element
will display a border, unless this default is overridden using CSS; the
exception is Opera, which doesn’t apply a border in this
scenario.
The a element has a number
of special attributes, which are detailed below, but the one that you’ll
use most of the time—if it’s not the only one you’ll use—is the
href attribute. This attribute indicates the link’s
destination, be that another web page, a section of the same web page, or
some other type of document, such as an image, a spreadsheet, or a PDF
document.
If no additional styles are applied using CSS, links will appear as follows:
- An unvisited link appears in blue underlined text.
- A visited link displays in purple underlined text.
- An active link—the link state during the (usually) very brief moment between the link’s activation and the loading of the next page—appears in red underlined text.
These color codes are replicated in the border of any
image that’s contained inside an a element (unless it’s
disabled in CSS). The example code referenced above displays in all
browsers, as shown in the image Figure 1.
Example
The
a element is used here to link to a page that lists
cakes for sale:
<p>You can try our <a href="cakes.html">lovely range of cakes</a>.</p>
Use This For …
This element is
used to contain a—preferably short—link text phrase, or an image (with an
appropriate alt attribute) that defines the
destination of the link.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
It causes no compatibility issues, and has excellent support across all tested browsers.
In this Section
accesskey
assigns a key to trigger the activation of this linkcharset
defines the character set used in the referenced documentcoords
specifies the x and y coordinates that define the boundaries of theahref
defines the destination of the linkhreflang
defines the language used in the referenced documentname
provides a reference point for same-page links to jump torel
defines the relationship between the referencing and referenced documentsrev
defines the relationship of this document from the point of view of the document to which it linksshape
categorizes the shape of thea’s hotspottabindex
indicates the link’s order in the logical tabbing sequence for the pagetarget
defines theframe(in frameset-based designs) that will display the linked page specified in thehref
User-contributed notes
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.