Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML tag

HTML tag

Example

Link to Runoob Tutorial:

<

a

href

=

"

https://www.runoob.com

"

Visit Runoob Tutorial!

a

Try it »

(More examples are at the bottom of the page)


Browser support

Element
Yes Yes Yes Yes Yes

All major browsers support tag.


Tag Definition and Usage Notes

The tag defines a hyperlink, used to link from one page to another.

The most important attribute of the element is the href attribute, which specifies the target of the link.

In all browsers, the default appearance of a link is as follows:

  • An unvisited link is underlined and blue
  • A visited link is underlined and purple
  • An active link is 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 tag can be either a hyperlink or an anchor. In HTML5, the tag is a hyperlink, but if there is no href attribute, it is just a placeholder for a hyperlink.

HTML5 has some new attributes and no longer supports some HTML 4.01 attributes.


property

New : New attributes in HTML5.

property 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 that the link is to be downloaded
href URL Specifies the target URL of the link.
hreflang language_code Specifies the base language of the target URL. Used only when the href attribute is present.
mediaNew media_query Specifies the media type of the target URL. Default: all. Used only when the href attribute is present.
name section_name Not supported in HTML5. Specifies the name of the anchor.
rel alternate
 author       
 bookmark       
 help       
 license       
 next       
 nofollow       
 noreferrer       
 prefetch       
 prev       
 search       
 tag | Specifies当前文档与目标 URL 之间的关系。仅在 href 属性存在时使用。 |

| 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. Used only when the href attribute is present.

| | [type](/tags/att-a-type.html) New | *MIME_type* | Specifies the MIME type of the target URL. Used only when the href attribute is present. Note: MIME = Multipurpose Internet Mail Extensions. |

Global Attributes

The tag supports HTML Global Attributes.


Event attribute

The tag supports HTML Event Attributes.


Try it - Example

Creating a Hyperlink
This example demonstrates how to create a link in an HTML document.

Using an Image as a Link
This example demonstrates how to use an image as a link.

Opening a Link in a New Browser Window
This example demonstrates how to open a page in a new window so that visitors do not need to leave your site.

Creating an Email Link
This example demonstrates how to link to an email. (This example only works after a mail client program is installed.)

Creating an Email Link 2
This example demonstrates a more complex email link.

Using an Anchor 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 the page (the name attribute is not supported in HTML5).


Related Articles

HTML Tutorial:HTML links

HTML DOM Reference Manual: Anchor Object