HTML <link> rel 属性
定义和用法
必需的 rel
属性指定当前文档和被链接文档/资源之间的关系。
实例
例子 1
导入外部样式表:
<link rel="stylesheet" href="styles.css">
例子 2
以下是将网站图标添加到网站的方法:
<!DOCTYPE html> <html> <head> <title>My Page Title</title> <link rel="icon" type="image/x-icon" href="favicon.ico"> </head> <body> <h1>This is a Heading</h1> <p>This is a paragraph.</p> </body> </html>
语法
<link rel="value">
属性值
值 | 描述 |
---|---|
alternate |
提供指向文档替代表示的链接(例如打印页面、翻译或镜像)。 例子:<link rel="alternate" type="application/atom+xml" href="/blog/news/atom"> |
author | 提供文档作者的链接。 |
dns-prefetch | 规定浏览器应该抢先执行目标资源所在源的 DNS 解析。 |
help |
提供指向帮助文档的链接。 例子:<link rel="help" href="/help/"> |
icon |
导入表示文档的图标。 例子:<link rel="icon" href="favicon.ico" type="image/x-icon"> |
license | 提供文档版权信息的链接。 |
next | 提供指向系列中下一篇文档的链接。 |
pingback | 提供处理对当前文档的 pingback 的 pingback 服务器的地址。 |
preconnect | Specifies that the browser should proactively connect to the origin of the target resource. |
prefetch | Specifies that the browser should proactively fetch and cache the target resource because it may be used in subsequent navigation. |
preload | Specifies that the browser agent must proactively fetch and cache the target resource based on the destination provided by the 'as' attribute (and the priority associated with that destination). |
prerender |
Specifies that the browser should pre-render (load) the specified web page in the background. If the user navigates to this page, it will speed up page loading (because the page has already been loaded). Warning! This will waste user bandwidth! Only use pre-rendering when you are absolutely sure that the web page is necessary at some point during the user's browsing process. |
prev | Indicates that this file is part of a series and that the previous file in the series is the referenced file. |
search | Provide links to resources that can be used to search the current document and related pages. |
stylesheet | Import stylesheets. |
Browser support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |