The Anchor element in HTML
View original- current
Summary (TL;DR)
An anchor marks hypertext link start or destination. HREF defines link target, NAME marks destination. Other optional attributes: REL/REV for link relationships, URN for resource number, TITLE, METHODS. At least HREF or NAME needed.
Anchors
An anchor is a piece of text which marks the beginning and/or the end of a hypertext link.
The text between the opening tag and the closing tag is either the start or destination (or both) of a link. Attributes of the anchor tag are as follows.
- HREF
- OPTIONAL. If the HREF attribute is present,
the anchor is sensitive text: the start of a link.
If the reader selects this text, (s)he should be presented with
another document whose network address is defined by the value
of the HREF attribute . The format of the network address is
specified elsewhere. This allows for the form HREF="#identifier"
to refer to another anchor in the same document.
If the anchor is in another document, the attribute is a relative name, relative to the documents address (or specified
base address if any).
- @@NOTE:
- This refers to the URI specification, which does not cover relative addresses. There is no specification of how to distinguish relative addresses from absolute addresses.
- NAME
- OPTIONAL. If present, the attribute NAME allows the anchor
to be the destination of a link. The value of the attribute is
an identifier for the anchor. Identifiers are arbitrary strings
but must be unique within the HTML document.
Another document can then make a reference explicitly to this
anchor by putting the identifier after the address,
separated by a hash sign.
- @@NOTE:
- This feature is representable in SGML as an ID attribute, if we restrict the identifiers to be SGML names.
- REL
- OPTIONAL. An attribute REL may give the relationship (s) described by the hypertext link. The value is a comma-separated list of relationship values. Values and their semantics will be registered by the HTML registration authority. The default relationship if none other is given is void. REL should not be present unless HREF is present.
- REV
- OPTIONAL. The same as REL, but the semantics of the link type are in the reverse direction. A link from A to B with REL="X" expresses the same relationship as a link from B to A with REV="X". An anchor may have both REL and REV attributes.
- URN
- OPTIONAL. If present, this specifies a uniform resource number for the document.
- TITLE
- OPTIONAL. This is informational only. If present the value of this field should equal the value of the TITLE of the document whose address is given by the HREF attribute.
- METHODS
- OPTIONAL. The value of this field is a string which if present must be a comma separated list of HTTP METHODS supported by the object for public use.
All attributes are optional, although one of NAME and HREF is necessary for the anchor to be useful. See also: LINK .
Example of use:
See <A HREF="http://www.w3.org/">CERN</A>'s information for more details. A <A NAME=serious>serious</A> crime is one which is associated with imprisonment. ... The Organization may refuse employment to anyone convicted of a <a href="#serious">serious</A> crime.