HTML <a>Tag
Examples
Link to Example:
Try it Yourself »
(More examples at the bottom of the page)
Browser Support
| Element | |||||
|---|---|---|---|---|---|
| <a> | Yes | Yes | Yes | Yes | Yes |
All major browsers support the <a> tag.
Definition and Usage
The <a> tag defines a hyperlink, used to link from one page to another.
The most important attribute of the <a> element is the href attribute, which specifies the link's destination.
In all browsers, the default appearance of links is as follows:
- Unvisited links are underlined and blue
- Visited links are underlined and purple
- Active links are underlined and red
Tips and Notes
Tip:If the href attribute is not used, the hreflang, media, rel, target, and type attributes cannot be used.
Tip:The linked page is usually displayed in the current browser window, unless another target is specified.
Tip:Please use CSS to change the style of links.
Differences between HTML 4.01 and HTML5
In HTML 4.01, the <a> tag could be either a hyperlink or an anchor. In HTML5, the <a> tag is a hyperlink, but if it has no href attribute, it is only a placeholder for a hyperlink.
HTML5 has some new attributes, and some HTML 4.01 attributes are no longer supported.
Attributes
New: New in HTML5.
| Attribute | Value | Description |
|---|---|---|
| charset | char_encoding | Not supported in HTML5.Specifies the character encoding of the target URL. |
| coords | coordinates | Not supported in HTML5.Specifies the coordinates of the link. |
| downloadNew | filename | Specifies a download link. |
| href | URL | Specifies the target URL of the link. |
| hreflang | language_code | Specifies the base language of the target URL. Only used when the href attribute is present. |
| mediaNew | media_query | Specifies the media type of the target URL. Default value: all. Only used when the href attribute is present. |
| name | section_name | Not supported in HTML5.Specifies the name of an anchor. |
| rel | alternate author bookmark help license next nofollow noreferrer prefetch prev search tag |
Specifies the relationship between the current document and the target URL. Only used when the href attribute is present. |
| rev | text | Not supported in HTML5.Specifies the relationship between the target URL and the current document. |
| shape | default rect circle poly |
Not supported in HTML5.Specifies the shape of the link. |
| target | _blank _parent _self _top framename |
Specifies where to open the target URL. Only used when the href attribute is present.
|
| type New | MIME_type | Specifies the MIME type of the target URL. Only used when the href attribute is present. Note: MIME = Multipurpose Internet Mail Extensions. |
Global Attributes
The <a> tag supportsHTML Global Attributes。
Event Attributes
The <a> tag supportsHTML Event Attributes。
Try it Yourself - Examples
Create hyperlinks
This example demonstrates how to create links in an HTML document.
Use an image as a link
This example demonstrates how to use an image as a link.
Open a link in a new browser window
This example demonstrates how to open a page in a new window, so visitors don't have to leave your site.
Create an email link
This example demonstrates how to link to an email. (This example works only after an email client program is installed.)
Create an email link 2
This example demonstrates a more complex email link.
Use anchors to jump to different positions on the same page
This example demonstrates how to use the id attribute of an anchor to jump to different positions on a page (HTML5 does not support the name attribute).
Related Articles
HTML Tutorial:HTML Links
HTML DOM Reference:Anchor Object
Other Extensions