HTML <a> Tag

Definition and Usage

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

<a> The most important attribute of the element is href attribute, it indicates the destination of the link.

By default, links will be displayed as follows in all browsers:

  • The link that has not been visited is underlined and blue
  • The link that has been visited is underlined and purple
  • The link being visited is underlined and red

提示:You may have noticed that the links on the CodeW3C.com site look very different from the default link appearance. You can use CSS ɗanɗo Add complex and diverse styles to text hyperlinks.

See also:

HTML Tutorial:HTML ɗabino

HTML DOM Reference Manual:Anchor Object

CSS Tutorial:Link Styles

Terminology Explanation

Koyarwa kogin kaiwai?

Dokar

Masanin 1

Rannu birnin ga codew3c.com

<a href="https://www.codew3c.com">Rannu codew3c.com!</a>

亲自试一试

Masanin 2

Kuwa zai nuna zai hukun imaja?

<a href="https://www.codew3c.com">
<img border="0" alt="W3School" src="w3logo.png" width="400" height="225">
</a>

亲自试一试

Masanin 3

Kuwa zai nuna zai hukun birnin kanan a baiye?

<a href="https://www.codew3c.com" target="_blank">Rannu codew3c.com!</a>

亲自试一试

Masanin 4

Kuwa zai nuna zai hukun birnin?

<a href="mailto:someone@example.com">Rannu birnin</a>

亲自试一试

Masanin 5

Kuwa zai nuna zai hukun fowon kanan?

<a href="tel:+8613888888888">+86 138 8888 8888</a>

亲自试一试

例子6

如何链接到同一页上的另一个部分:

<a href="#section2">转到第二章</a>

亲自试一试

例子7

如何链接到JavaScript:

<a href="javascript:alert('Hello World!');">执行JavaScript</a>

亲自试一试

提示和注释

提示:如果<a>标签没有href属性,它只是一个超链接的占位符。

提示:被链接的页面通常显示在当前浏览器窗口中,除非您规定了另一个目标(用target属性)。

提示:请使用CSS设置链接的样式:CSS ɗabinoCSS ɗanɗo

属性

属性 描述
download 文件名 规定当用户单击超链接时将下载目标。
href URL 规定链接指向的页面的URL。
hreflang 语言代码 规定被链接文档的语言。
media 媒体查询 规定被链接文档是为何种媒介/设备优化的。
ping URL列表 规定以空格分隔的URL列表,当链接被访问时,浏览器将发送带有ping正文的POST请求(在后台发送)。通常用于跟踪。
referrerpolicy
  • no-referrer
  • no-referrer-when-downgrade
  • origin
  • origin-when-cross-origin
  • same-origin
  • strict-origin-when-cross-origin
  • unsafe-url
规定要与链接一起发送的引用信息。
rel
  • alternate
  • author
  • bookmark
  • external
  • help
  • license
  • next
  • nofollow
  • noreferrer
  • noopener
  • prev
  • search
  • tag
规定当前文档和被链接文档之间的关系。
target
  • _blank
  • _parent
  • _self
  • _top
规定在何处打开被链接文档。
type 媒体类型 规定被链接文档的媒体类型。

全局属性

<a> 标签还支持 HTML中的全局属性

事件属性

<a> 标签还支持 HTML中的事件属性

默认的 CSS 设置

大多数浏览器将使用以下默认值显示 <a> 元素:

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

ɗanin

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
ɗanin ɗanin ɗanin ɗanin ɗanin