<a href> Tag Syntax

<body>
   ...
   ... flow content expected ...
   <a href="target-URI" ...>
      ... flow content ...
   </a>
   ...
   ... phrasing content expected ...<a href="target-URI">... phrasing content ...</a>...
   ...
</body>
Rules for coding the HTML a element

Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.

  1. Code the a element for a hypertext link where either flow content is expected or phrasing content is expected.
  2. Begin the a element with a starting <a> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the xmlns attribute on the <html> tag.
  3. Code an href attribute with the hash of an id within the same page, a URL of another web page or a URI such as a mailto: link.
  4. Include any other attributes of the <a> tag as appropriate.
  5. Inside the a element, code the text or other phrasing content that is to appear as the hypertext link. If the <a> tag is coded where flow content is permitted, then the inner HTML of the <a> tag may contain flow content also.
  6. End the a element with a matching </a> closing tag.

<a href/> Content Model

Contents of the <a href/> Tag
When coded in flow content

When coded in flow content, the content of the a element can include HTML comments, text content and any HTML tags that can be used in flow content.

When coded in phrasing content

When coded in phrasing content, the content of the a element can include HTML comments, text content and only those HTML tags that can be used in phrasing content.

Recommendation

The <a> tag can be combined with many other phrasing content tags, such as:

<abbr>
when the text in the link is an acronym or abbreviation
<cite>
for a link to a web site whose content is being cited, or to a web site related to a creative work being cited
<code>
when the text in the link represents computer code, such as when the pages on this site link to the description and syntax of tags in the tag reference
<img>
when the link is an image rather than text
<kbd>
when the text in the link represents keyboard input
<mark>
when the text in the link represents the search term(s) in search results
<output>
when the text in the link represents computer output
<time>
when the text in the link represents a time, which may be used to link to the full description of an entry in the chronological summary of some type of log or a blog
<var>
when the text in the link represents a variable that is to be replaced with an actual value

When their content is to be applied to the entire link, the <a> tag can be nested inside those tags, if their content model allows phrasing content, or those tags can be nested inside the <a> tag. For tags with no allowable content, such as the <img> tag, those tags must be coded inside the <a> tag. Our recommendation is to always code them inside the <a> tag, since that makes it easier to make changes to the HTML code later. For example:

<p>According to <a href="http://www.AuthoringHTML.com/"><cite>Authoring HTML</cite></a>,
   the &lt;cite&gt; tag should be used for the title of a creative work, not the cited content.
</p>

To make it clear that the citation comes from a book, you would simply need to add the word "book" between the <cite> tag and the ending </a> tag.

<p>According to the <a href="http://www.AuthoringHTML.com/"><cite>Authoring HTML</cite> book</a>,
   the &lt;cite&gt; tag should be used for the title of a creative work, not the cited content.
</p>