jump

HTML: The Markup Language

ahyperlink CHANGED # T

The a element represents a hyperlink.

Permitted contents #

Permitted attributes #

global attributes
Any attributes permitted globally.
name = ID OBSOLETE #
Specifies that its a element is a named hyperlink, with the name given by the value of this attribute.
The name attribute on the a element is obsolete. Consider putting an id attribute on the nearest container instead.
Any string, with the following restrictions:

Previous versions of HTML placed greater restrictions on the content of ID values (for example, they did not permit ID values to begin with a number).

href = URL potentially surrounded by spaces #
A URL that provides the destination of the hyperlink. If the href attribute is not specified, the element represents a placeholder hyperlink.
target = browsing-context name or keyword CHANGED #
A name or keyword giving a browsing context for UAs to use when following the hyperlink.
The target attribute on the a element was deprecated in a previous version of HTML, but is no longer deprecated, as it useful in Web applications, particularly in combination with the iframe element.
Any string that is either of the following:
rel = set of space-separated tokens #
A list of tokens that specify the relationship between the document containing the hyperlink and the destination indicated by the hyperlink.
hreflang = language tag #
The language of the destination of the hyperlink.
A valid language tag as defined in [BCP 47].
media = media-query list NEW #
The media for which the destination of the hyperlink was designed.
A valid media query list as defined in [Media Queries].
type = MIME type #
The MIME type of the destination of the hyperlink.
A string that identifies a valid MIME media type as defined in [RFC 2046].

Additional constraints and admonitions #

Tag omission #

An a element must have both a start tag and an end tag.

Permitted parent elements #

any element that can contain phrasing elements, any element that can contain flow elements

Changes in HTML5 #

Although previous versions of HTML restricted the a element to only containing phrasing content (essentially, what was in previous versions referred to as “inline” content), the a element is now transparent; that is, an instance of the a element is now allowed to also contain flow content (essentially, what was in previous versions referred to as “block” content)—if the parent element of that instance of the a element is an element that is allowed to contain flow content.

Details #

If the contents of an a element are empty, the element represents an empty hyperlink.

DOM interface #

interface HTMLAnchorElement : HTMLElement {
  stringifier attribute DOMString href;
           attribute DOMString target;
           attribute DOMString rel;
  readonly attribute DOMTokenList relList;
           attribute DOMString media;
           attribute DOMString hreflang;
           attribute DOMString type;

           attribute DOMString text;

  // URL decomposition IDL attributes
           attribute DOMString protocol;
           attribute DOMString host;
           attribute DOMString hostname;
           attribute DOMString port;
           attribute DOMString pathname;
           attribute DOMString search;
           attribute DOMString hash;
};

Typical default display properties #

a:link, a:visited {
color: (internal value);
text-decoration: underline;
cursor: auto; }
a:link:active, a:visited:active {
color: (internal value); }

Examples #

A hyperlink intended to be useful in output for all media types except the print media type.

<a href="./page2.html" rel=next media="not print">next</a>

The name attribute is obsolete.

<a name="section5"/>

A placeholder hyperlink.

<a>prev</a>

A hyperlink that will cause its target to be opened in a new browsing context.

<a href="http://help.example.com" target="_blank">Help</a>

The value of the href attribute contains a space character.

some <a href="http://example.com/Archive/Public Data/">public</a> data is also available

A hyperlink that represents multiple link types.

<a href="../toc.html" rel="index up">up</a>

A hyperlink that contains a paragraph.

<a href="javascript:void(0);"
  onmouseover="return anno('Note: This paragraph is informative only.')
  onmouseout="return anno_bye();">
<p>The following is introductory information…</p>
</a>