a Element


 

Module

The a element is an inline element declared by the XHTML 1.1 Hypertext Module

This is the only element in this Module.

Description

The a element is primarily used to create hyperlinks. The link's target is a URI which is specified by the href attribute (which is of type URI).

Optionally, the language of the content at that URI (and/or its character set) may be stated using the the hreflang attribute (and/or charset attribute). If the content at the target URI is of an unusual MIME type, you may want to specify this using the type attribute - this content type information is usually provided as an indication to the user agent which may, for example, decide not to try to follow a link to an unsupported MIME type. Note that it is the responsibility of the document's author to ensure that the information provided in the hreflang, charset and type attributes is correct.

The title attribute may be used to supply additional information about the link's target, although the element's content should provide a basic description. Links with uninformative content - such as "here", "click here" and "this link" - should be avoided. Many assistive technologies - such as screen readers - present their users with a list of all the links on a page, out of context. Link text such as "click here" is next-to-useless for these users. Good link text is more than just an accessibility consideration, however: it makes content much more informative to those scanning a website for the first time... and first impressions count!

Historically, the a element was known as the 'anchor' element since it was commonly used to specify an anchor point mid-way through a document. This point in the document could then be linked to directly - by another hyperlink - using the name attribute of the anchor element as a fragment identifier. In more modern browsers, however, an anchor point may be created at almost any element, simply by adding an id attribute which is then used as the fragment identifier. The name attribute of the a element has been removed in XHTML 1.1. Of course, there is nothing to stop you creating an anchor such as <h2><a id="sect2">Section 2</a></h2> in XHTML 1.1, but there is no need: <h2 id="sect2">Section 2</h2> would do equally well. Whilst it is true that some very old browsers don't support id attributes as fragment identifiers, they are so outdated that this is no longer seen as an issue (ref: W3C Note (work in progress) *XHTML Media Types - Compatibility Guidelines - Item A.8).

The relationship between the current page and the target page may be specified using the rel or rev attributes. For example, in a page of technical specifications, the hyperlink to a glossary of terms may include the rel="glossary" attribute: rel defines a forward relationship. Alternatively, the glossary page itself may contain a link to the technical specifications with the attribute rev="glossary" since rev defines a reverse relationship. For more information on values for these two attributes, see the LinkTypes attribute type.

A few examples:

  • <a href="http://www.lemonde.fr/" hreflang="fr"><span xml:lang="fr">Le Monde</span> in French</a>
  • <a href="soundtrack.mp3" type="audio/mpeg">Soundtrack Sample</a>
  • <p>Skip to <a href="#content">Page Content</a></p>
  • <a href="glossary.html" rel="glossary">Glossary</a> (link in technical.html)
  • <a href="technical.html" rev="glossary">Technical Information</a> (link in glossary.html)

See the map element for details on using the a element in client side image maps.

#REQUIRED Attributes

There are no #REQUIRED attributes on the a element.


Specific Attributes

Specific attributes of the a element are listed below:

From the Hypertext Module - the Element's own Module

accesskey [ type Character ]
Key to allow keyboard activation of the hyperlink
charset [ type Charset ]
The character encoding of the resource at the URI specified by the href attribute
href [ type URI ]
The destination URI of the link
hreflang [ type LanguageCode ]
The language code of the resource at the URI specified by the href attribute (should not be used if href is not specified)
rel [ type LinkTypes ]
Specifies the (forward) relationship from the current document to the resource specified by the href attribute - e.g. a value of "glossary" specifies that the resource is a glossary for the current document (if desired, a space separated list of relationships may be given)
rev [ type LinkTypes ]
Specifies the reverse relationship between the current document and the resource specified by the href attribute - i.e. the relationship from that other resource to the current document - e.g. a value of "glossary" specifies that the current document is a glossary for the resource (if desired, a space separated list of relationships may be given)
tabindex [ type Number ]
An integer between 0 and 32767 specifying the position of the link in the tabbing order of the document
type [ type ContentType ]
The content type of the resource at the URI specified by the href attribute

From the Client-side Image Map Module

coords [ type Coords ]
In a client-side image map, this specifies the coordinates applying to the shape
shape [ type Shape (rect | circle | poly | default) - default="rect" ]
In a client-side image map, this specifies the shape of the region which applies to the link - the coords attribute specifies the shape's dimensions

From the Intrinsic Events Module

onblur [ type Script ]
Script to be executed when the element loses focus, for example when tabbed away from
onfocus [ type Script ]
Script to be executed when the element receives focus, for example either when tabbed to via the keyboard or when the link is clicked using a mouse

From the Target Module

target [ type FrameTarget ]
Indicates the window or frame in which to open the link

Common Attributes

Common attributes of the a element are listed below:

From the Core Attribute Collection

class [ type NMTOKENS ]
One or more space separated classes
id [ type ID ]
A unique identifier for the element
style [ type CDATA ], from the Style Attribute Module (deprecated)
Element-specific styles
title [ type Text ]
Descriptive title for the element (in some user agents this may appear as a "tooltip" when the mouse hovers over the element)
xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]
XML namespace

From the I18N Attribute Collection

dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Module
Left-to-right or right-to-left directionality
xml:lang [ type LanguageCode ]
A language code for the element

From the Events Attribute Collection

All attributes in the Events Attribute Collection are supported:
onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup


Content Model

The Content Model for the a element is:

( #PCDATA | InlNoAnchor.mix )*

See Content Model & Nesting for information about Content Model syntax and Nesting Groups.

Valid children of a

Note: An a element must never contain another a element, at any nesting depth. See Descendant Exclusions.

Valid parents of a


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 01 Oct 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Element Index (XHTML 1.1) > a Element