HTML and CSS Reference
In-Depth Information
Interpreting the
<a>
Tag in Different Versions of HTML
The
<a>
tag is treated slightly differently in versions of HTML prior to HTML5. In
HTML 4.01 and XHTML, the
<a>
tag can be used to enclose only text-level elements and
should not be used to group content or structural elements. This means that the code
<a href=”home.htm”>
<p>Go to the home page</p>
</a>
would not be allowed because the hyperlink is applied to an entire paragraph. HTML5
does not make this distinction, allowing the
<a>
tag to enclose text-level, grouping, and
structural elements.
A second important difference is that in HTML 4.01 and XHTML, the
<a>
tag can also
be used as an anchor to mark specific locations within the document. For that reason,
the
<a>
tag is commonly referred to as the tag for the
anchor
element. HTML5 does not
support this interpretation; the
<a>
tag can be used only to mark hypertext links.
Attributes of the
a
Element
The
a
element supports several attributes in addition to the
href
attribute. Some of these
attributes are listed in Figure 2-13.
Figure 2-13
Attributes of the anchor (a) element
Attribute Description
charset=”
encoding
”
Specifies the character encoding used in the linked resource (
not
supported in HTML5
)
href=”
url
”
Indicates the resource targeted by the hypertext link
media=”
media type
”
Indicates the media device in which the linked resource should be
viewed (
HTML5
)
name=”
name
”
Assigns a name for the section anchored by the <a> tag (
not
supported in HTML5
)
rel=”
relationship
”
Specifies the relationship between the current document and the
linked resource
ping=”
url
”
A space-separated list of resources that get notified when the user
follows the hyperlink (
HTML5
)
target=”
target_type
”
Specifies where to open the linked resource
type=”
mime-type
”
Specifies the content (the mime-type) of the linked resource