HTML Tag Reference - HTML tag <a>








This element defines a hyperlink, the named target destination for a hyperlink, or both.

href attribute has the URL linking to other web page or resource. label is used to display information for web page visitors.

<a href="http://www.example.com">label</a>

Anchor name starts with #. It marks a linkable area inside a page. We can use anchor link to hyperlink to a specific part in a web page.

<a href="#anchorName">label</a>

Standard Syntax

<a
    accesskey="key"
    charset="character code for language of linked resource"
    class="class name(s)"
    coords="comma-separated list of numbers" 
    dir="ltr | rtl"
    href="URL" hreflang="language code"
    id="unique alphanumeric identifier" 
    lang="language code"
    name="name of target location"
    rel="comma-separated list of relationship values" 
    rev="comma-separated list of relationship values" 
    shape="default | circle | poly | rect" 
    style="style information"
    tabindex="number"
    target="frame or window name | _blank | _parent | _self | _top" 
    title="advisory text"
    type="content type of linked data"
>

</a>




Browser compatibility

<a> Yes Yes Yes Yes Yes

What's new in HTML5

HTML5 has some new attributes, and some HTML 4.01 attributes are deprecated.

Attribute

charset
char encoding of a linked document. Not supported in HTML5.
coords
the coordinates of a link. Not supported in HTML5.
download
the target will be downloaded when clicking the hyperlink. New in HTML5
href
the URL of the link
hreflang
the language code of the linked document
media
media/device the linked document is optimized for. New in HTML5.
name
Specifies the name of an anchor. Not supported in HTML5. Use the global id attribute instead.
rel
Possible values:alternate|author|bookmark|help|license|next|nofollow|noreferrer| prefetch|prev|search|tag. Relationship between the current document and the linked document
rev
Not supported in HTML5.
shape
Possible values:default|rect|circle|poly. Not supported in HTML5. The shape of a link
target
Possible values:_blank|_parent|_self|_top|framename. Where to open the linked document.
type
New in HTML5. Media type of the linked document.

Global Attributes

The <a> tag supports the Global Attributes in HTML.

Event Attributes

The <a> tag supports the Event Attributes in HTML.

Default CSS Settings

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

a:link:active, a:visited:active { 
    color: (internal value);
}




Example

A demo showing how to use anchor tag to create hyperlink and anchor.

<html>
<body>
     <a name="top"></a>
     <a href="http://www.java2s.com">java2s.com</a>
     <a href="#par3">Go to paragraph #3 in this page</a>
     <p><a href="yourdocument.html#sty">
        Go to the yourdocument.htm page,sty location</a></p>
     <p><a name="par3">Paragraph #3</a></p>
     <p><a href="#top">Top</a></p>
</body><!-- w w  w  .  j  ava 2s.  c o  m-->
</html>

Click to view the demo