HTML 标签的 href 属性
href 属性规定被链接文档的位置(URL)。适用于<a>,<area>,<base>,<link>等标签。
实例
在下面的例子中,href 属性指向了一个外部样式表的位置:
<html><head><link rel="stylesheet" type="text/css" href="/html/csstest1.css"></head><body><h1>我通过外部样式表进行格式化。</h1><p>我也一样!</p></body></html>
定义和用法
href 属性规定被链接文档的位置(URL)。适用于<a>,<area>,<base>,<link>等标签。
提示和注释
注释:如果需要,应该对所有的 URL 进行 URL 编码。
语法
<link href="value">
属性值
| 值 | 描述 |
|---|---|
| URL | 超链接的 URL。可能的值:
|
更多实例
<!DOCTYPE html><html><body><h1>a 标签的 href 属性</h1><p>绝对地址url: <a href="https://cankaoshouce.com">参考手册</a></p><p>相对地址url: <a href="/html-attribute/html-href.html">HTML 标签的 href 属性</a></p></body></html>
<img src="planets.gif" width="145" height="126" alt="Planets"usemap="#planetmap"><map name="planetmap"><area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun"><area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury"><area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus"></map>
<!DOCTYPE html><html><head><base href="https://cankaoshouce.com/images/"></head><body><h1>The base href attribute</h1><p><img src="demo.png" width="24" height="39" alt="Stickman"> - 请注意,我们只为图像指定了一个相对地址。因为我们已经在head部分指定了一个基本URL,所以浏览器将在 "https://cankaoshouce.com/images/demo.png" 定位到图片。</p></body></html>