HTML <a> tag href attribute

example

The href attribute specifies the target of the link:

<a href="http://www.w3school.com.cn">W3School</a>

try it yourself

Definition and Usage

The href attribute of the <a> tag is used to specify the URL of the hyperlink target.

The value of the href attribute can be the relative or absolute URL of any valid document, including fragment identifiers and JavaScript code snippets. If the user selects content within an <a> tag, the browser attempts to retrieve and display the document represented by the URL specified by the href attribute, or execute a list of JavaScript expressions, methods, and functions.

Tips and Notes

Note: The href attribute or name attribute must be provided in the <a> tag.

Make text links

A simple <a> tag that references other documents can be of the form:

<a href="http://www.w3school.com.cn/index.html">W3School 在线教程</a>

The browser displays the phrase "W3School Online Tutorial" (usually underlined blue text) with a special effect, so the user knows it's a hyperlink that can link to other documents. like this:

W3School Online Tutorial

Users can also use the options in the browser to specify the text color, set the color of the link text before and after the link.

Tip: You can add complex and varied styles to text hyperlinksusing  CSS pseudo-classes .

Make image links

More complex anchors can also contain images. The following LOGO is an image link, click on the image to return to the home page of W3school:

<a href="http://www.w3school.com.cn/index.html">
<img src="/i/w3school_logo_white.gif" />
</a>

上面的代码会为 W3School 的 LOGO 添加一个返回首页的超链接:

W3School 在线教程

大多数图形浏览器都会在作为锚的一部分的图像周围放置特殊的边框。通过在 <img> 标签中把图像的 border 属性设置为 0 可以删除超链接的边框。也可以使用 CSS 的边框属性来全局性地改变元素的边框样式。

语法

<a href="value">

属性值

描述
URL 超链接的 URL。可能的值:
  • 绝对 URL - 指向另一个站点(比如 href="http://www.example.com/index.htm")
  • 相对 URL - 指向站点内的某个文件(href="index.htm")
  • 锚 URL - 指向页面中的锚(href="#top")

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324502738&siteId=291194637