HTML href 属性


定义和用法

对于 <a> 和 <area> 元素,href 属性指定链接指向的页面的 URL。

对于 <base> 元素,href 属性指定页面上所有相对 URL 的基本 URL。

对于 <link> 元素,href 属性指定外部资源(通常是样式表文件)的位置(URL)。


适用于

href 属性可用于以下元素:

元素 属性
<a> href
<area> href
<base> href
<link> href

实例

A 实例

href 属性指定链接的目的地:

<a href="https://www.w3schools.cn">访问 W3Schools</a>
亲自试一试 »

Area 实例

图像映射,带有可点击区域:

<img src="planets.gif" width="145" height="126" alt="行星"
usemap="#planetmap">

<map name="planetmap">
  <area shape="rect" coords="0,0,82,126" href="sun.htm" alt="太阳">
  <area shape="circle" coords="90,58,3" href="mercur.htm" alt="水星">
  <area shape="circle" coords="124,58,8" href="venus.htm" alt="金星">
</map>
亲自试一试 »

Base 实例

为页面上的所有相对 URL 指定一个基本 URL:

<head>
<base href="https://www.w3schools.cn/images/">
</head>
亲自试一试 »

Link 实例

链接到外部样式表:

<link rel="stylesheet" type="text/css" href="theme.css">
亲自试一试 »

浏览器支持

href 属性对每个元素都有以下浏览器支持:

元素
a Yes Yes Yes Yes Yes
area Yes Yes Yes Yes Yes
base Yes Yes Yes Yes Yes
link Yes Yes Yes Yes Yes