HTML <a> tag
Examples
Link to this tutorial:
try it"
(For more examples, see the bottom of the page)
Browser Support
All major browsers support <a> label.
Tag definitions and instructions
<a> tag defines a hyperlink from one page to link to another page.
The most important element is the href attribute <a> attribute that specifies the link target.
In all browsers, the default link looks like this:
- Not visited link is underlined and blue
- Has been visited link is underlined and purple
- Active link is underlined and red
Tips and Notes
Tip: If you do not use the href attribute, you can not use hreflang, media, rel, target and type properties.
Tip: normally displayed in the current browser window linked pages, unless the provisions of the other target.
Tip: Use CSS to change the style of the link.
Differences between HTML 4.01 and HTML5
In HTML 4.01, <a> tag can be both a hyperlink, it can be anchored. In HTML5, <a> label is a hyperlink, but if there is no href attribute, it is just a placeholder for a hyperlink.
HTML5 has some new attributes, while no longer supports some HTML 4.01 attributes.
Attributes
New: HTML5 new property.
属性 | 值 | 描述 |
---|---|---|
charset | char_encoding | HTML5 不支持。规定目标 URL 的字符编码。 |
coords | coordinates | HTML5 不支持。规定链接的坐标。 |
download New | filename | 指定下载链接 |
href | URL | 规定链接的目标 URL。 |
hreflang | language_code | 规定目标 URL 的基准语言。仅在 href 属性存在时使用。 |
media New | media_query | 规定目标 URL 的媒介类型。默认值:all。仅在 href 属性存在时使用。 |
name | section_name | HTML5 不支持。规定锚的名称。 |
rel | alternate author bookmark help license next nofollow noreferrer prefetch prev search tag |
规定当前文档与目标 URL 之间的关系。仅在 href 属性存在时使用。 |
rev | text | HTML5 不支持。规定目标 URL 与当前文档之间的关系。 |
shape | default rect circle poly |
HTML5 不支持。规定链接的形状。 |
target | _blank _parent _self _top framename |
规定在何处打开目标 URL。仅在 href 属性存在时使用。 |
type New | MIME_type | 规定目标 URL 的 MIME 类型。仅在 href 属性存在时使用。 注:MIME = Multipurpose Internet Mail Extensions。 |
Global Properties
<a> tag supports HTML global properties .
Event Properties
<a> tag supports HTML event properties .
Try - Example
Creating hyperlinks
This example demonstrates how to create a link in an HTML document.
An image as a link
This example demonstrates how to use an image as a link.
Open link in a new browser window
This example demonstrates how to open a page in a new window, so visitors do not need to leave your site up.
Create e-mail link
This example demonstrates how to link a message. (In this case to work after you install the mail client.)
Create e-mail link 2
This example demonstrates a more complex e-mail link.
Use anchors to jump to a different location on the same page
This example demonstrates how to use the id attribute anchor jump to a different position on the page (HTML5 does not support name attribute).
related articles
HTML Tutorial: HTML link
HTML DOM Reference: Anchor objects