1. 4.6 Links
      1. 4.6.1 概述
      2. 4.6.2 Links created by a and area elements
      3. 4.6.3 API for a and area elements
      4. 4.6.4 Following hyperlinks
      5. 4.6.5 Downloading resources
        1. 4.6.5.1 Hyperlink auditing
      6. 4.6.6 Link types
        1. 4.6.6.1 Link type "alternate"
        2. 4.6.6.2 "author" 链接类型
        3. 4.6.6.3 "bookmark" 链接类型
        4. 4.6.6.4 Link type "canonical"
        5. 4.6.6.5 "dns-prefetch" 链接类型
        6. 4.6.6.6 "external" 链接类型
        7. 4.6.6.7 "help" 链接类型
        8. 4.6.6.8 Link type "icon"
        9. 4.6.6.9 "license" 链接类型
        10. 4.6.6.10 Link type "manifest"
        11. 4.6.6.11 Link type "modulepreload"
        12. 4.6.6.12 "nofollow" 链接类型
        13. 4.6.6.13 Link type "noopener"
        14. 4.6.6.14 Link type "noreferrer"
        15. 4.6.6.15 Link type "opener"
        16. 4.6.6.16 "pingback" 链接类型
        17. 4.6.6.17 "preconnect 链接类型"
        18. 4.6.6.18 "prefetch" 链接类型
        19. 4.6.6.19 Link type "preload"
        20. 4.6.6.20 "prerender" 链接类型
        21. 4.6.6.21 Link type "search"
        22. 4.6.6.22 Link type "stylesheet"
        23. 4.6.6.23 "tag" 链接类型
        24. 4.6.6.24 顺序链接类型
          1. 4.6.6.24.1 "next" 链接类型
          2. 4.6.6.24.2 "prev" 链接类型
        25. 4.6.6.25 其他链接类型

4.6.1 概述

链接是一种概念构造,由 a, arealink 元素创建, 表示 两个资源之间的联系,其中一个是当前 Document。 在 HTML 中有两种链接:

外部资源链接

这些链接指向的资源用于增强当前文档,通常由用户代理自动处理。

超链接

这些指向其他文档的链接通常通过用户代理暴露给用户,这样用户可以让用户代理 导航 到那些资源,例如在浏览器中访问或者下载它们。

对于有 href 属性和 rel 属性的 link 元素, 必须为 rel 属性的关键字按照 链接类型 部分的定义创建一个链接。

类似地,对于有 href 属性和 rel 属性的 aarea 元素, 必须为 rel 属性的关键字按照 链接类型 部分的定义创建一个链接。 与 link 元素不同,对于有 href 属性的 aarea 元素,如果没有 rel 属性或 rel 属性的关键字的定义中没有一个是用来指定 超链接 的,也必须创建一个 超链接。 这个暗示的超链接没有特殊含义(它也没有 链接类型),只是把该元素的 节点文档 链接到了该元素的 href 属性给出的资源。

超链接 可以有一个或更多的 超链接注释,用来修改这个超链接的处理语义。

The href attribute on a and area elements must have a value that is a valid URL potentially surrounded by spaces.

The href attribute on a and area elements is not required; when those elements do not have href attributes they do not create hyperlinks.

The target attribute, if present, must be a valid browsing context name or keyword. It gives the name of the browsing context that will be used. User agents use this name when following hyperlinks.

When an a or area element's activation behavior is invoked, the user agent may allow the user to indicate a preference regarding whether the hyperlink is to be used for navigation or whether the resource it specifies is to be downloaded.

In the absence of a user preference, the default should be navigation if the element has no download attribute, and should be to download the specified resource if it does.

Whether determined by the user's preferences or via the presence or absence of the attribute, if the decision is to use the hyperlink for navigation then the user agent must follow the hyperlink, and if the decision is to use the hyperlink to download a resource, the user agent must download the hyperlink. These terms are defined in subsequent sections below.

The download attribute, if present, indicates that the author intends the hyperlink to be used for downloading a resource. The attribute may have a value; the value, if any, specifies the default file name that the author recommends for use in labeling the resource in a local file system. There are no restrictions on allowed values, but authors are cautioned that most file systems have limitations with regard to what punctuation is supported in file names, and user agents are likely to adjust file names accordingly.

Element/a#attr-ping

Support in all current engines.

Firefox🔰 YesSafari6+Chrome12+
Opera15+Edge79+
Edge (Legacy)17+Internet ExplorerNo
Firefox AndroidNoSafari iOS6+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android14+

The ping attribute, if present, gives the URLs of the resources that are interested in being notified if the user follows the hyperlink. The value must be a set of space-separated tokens, each of which must be a valid non-empty URL whose scheme is an HTTP(S) scheme. The value is used by the user agent for hyperlink auditing.

The rel attribute on a and area elements controls what kinds of links the elements create. The attribute's value must be a unordered set of unique space-separated tokens. The allowed keywords and their meanings are defined below.

rel's supported tokens are the keywords defined in HTML link types which are allowed on a and area elements, impact the processing model, and are supported by the user agent. The possible supported tokens are noreferrer, noopener, and opener. rel's supported tokens must only include the tokens from this list that the user agent implements the processing model for.

The rel attribute has no default value. If the attribute is omitted or if none of the values in the attribute are recognized by the user agent, then the document has no particular relationship with the destination resource other than there being a hyperlink between the two.

The hreflang attribute on a elements that create hyperlinks, if present, gives the language of the linked resource. It is purely advisory. The value must be a valid BCP 47 language tag. [BCP47] User agents must not consider this attribute authoritative — upon fetching the resource, user agents must use only language information associated with the resource to determine its language, not metadata included in the link to the resource.

The type attribute, if present, gives the MIME type of the linked resource. It is purely advisory. The value must be a valid MIME type string. User agents must not consider the type attribute authoritative — upon fetching the resource, user agents must not use metadata included in the link to the resource to determine its type.

The referrerpolicy attribute is a referrer policy attribute. Its purpose is to set the referrer policy used when following hyperlinks. [REFERRERPOLICY]

4.6.3 API for a and area elements

interface mixin HTMLHyperlinkElementUtils {
  [CEReactions] stringifier attribute USVString href;
  readonly attribute USVString origin;
  [CEReactions] attribute USVString protocol;
  [CEReactions] attribute USVString username;
  [CEReactions] attribute USVString password;
  [CEReactions] attribute USVString host;
  [CEReactions] attribute USVString hostname;
  [CEReactions] attribute USVString port;
  [CEReactions] attribute USVString pathname;
  [CEReactions] attribute USVString search;
  [CEReactions] attribute USVString hash;
};
hyperlink . toString()
hyperlink . href

HTMLAnchorElement/href

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android12.1+

HTMLAnchorElement/toString

Support in all current engines.

Firefox22+SafariYesChrome52+
OperaYesEdge79+
Edge (Legacy)18Internet ExplorerNo
Firefox Android22+Safari iOSYesChrome Android52+WebView Android52+Samsung Internet6.0+Opera AndroidYes

HTMLAreaElement/href

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android12.1+

HTMLAreaElement/toString

Support in all current engines.

Firefox22+SafariYesChrome52+
OperaYesEdge79+
Edge (Legacy)18Internet ExplorerNo
Firefox Android22+Safari iOSYesChrome Android52+WebView Android52+Samsung Internet6.0+Opera AndroidYes

Returns the hyperlink's URL.

Can be set, to change the URL.

hyperlink . origin

HTMLAnchorElement/origin

Support in all current engines.

Firefox26+Safari5.1+Chrome8+
Opera15+Edge79+
Edge (Legacy)17+Internet ExplorerNo
Firefox Android26+Safari iOS5+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/origin

Support in all current engines.

Firefox26+Safari5.1+Chrome8+
Opera15+Edge79+
Edge (Legacy)17+Internet ExplorerNo
Firefox Android26+Safari iOS5+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's origin.

hyperlink . protocol

HTMLAnchorElement/protocol

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/protocol

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's scheme.

Can be set, to change the URL's scheme.

hyperlink . username

HTMLAnchorElement/username

Support in all current engines.

Firefox26+Safari10+Chrome32+
Opera19+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android26+Safari iOS10+Chrome Android32+WebView Android4.4.3+Samsung Internet2.0+Opera Android19+

HTMLAreaElement/username

Support in all current engines.

Firefox26+Safari10+Chrome32+
Opera19+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android26+Safari iOS10+Chrome Android32+WebView Android4.4.3+Samsung Internet2.0+Opera Android19+

Returns the hyperlink's URL's username.

Can be set, to change the URL's username.

hyperlink . password

HTMLAnchorElement/password

Support in all current engines.

Firefox26+Safari10+Chrome32+
Opera19+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android26+Safari iOS10+Chrome Android32+WebView Android4.4.3+Samsung Internet2.0+Opera Android19+

HTMLAreaElement/password

Support in all current engines.

Firefox26+Safari10+Chrome32+
Opera19+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android26+Safari iOS10+Chrome Android32+WebView Android4.4.3+Samsung Internet2.0+Opera Android19+

Returns the hyperlink's URL's password.

Can be set, to change the URL's password.

hyperlink . host

HTMLAnchorElement/host

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/host

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's host and port (if different from the default port for the scheme).

Can be set, to change the URL's host and port.

hyperlink . hostname

HTMLAnchorElement/hostname

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/hostname

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's host.

Can be set, to change the URL's host.

hyperlink . port

HTMLAnchorElement/port

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/port

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's port.

Can be set, to change the URL's port.

hyperlink . pathname

HTMLAnchorElement/pathname

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/pathname

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's path.

Can be set, to change the URL's path.

hyperlink . search

HTMLAnchorElement/search

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/search

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's query (includes leading "?" if non-empty).

Can be set, to change the URL's query (ignores leading "?").

hyperlink . hash

HTMLAnchorElement/hash

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

HTMLAreaElement/hash

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android14+

Returns the hyperlink's URL's fragment (includes leading "#" if non-empty).

Can be set, to change the URL's fragment (ignores leading "#").

An element implementing the HTMLHyperlinkElementUtils mixin has an associated url (null or a URL). It is initially null.

An element implementing the HTMLHyperlinkElementUtils mixin has an associated set the url algorithm, which runs these steps:

  1. If this element's href content attribute is absent, set this element's url to null.

  2. Otherwise, parse this element's href content attribute value relative to this element's node document. If parsing is successful, set this element's url to the result; otherwise, set this element's url to null.

When elements implementing the HTMLHyperlinkElementUtils mixin are created, and whenever those elements have their href content attribute set, changed, or removed, the user agent must set the url.

This is only observable for blob: URLs as parsing them involves a Blob URL Store lookup.

An element implementing the HTMLHyperlinkElementUtils mixin has an associated reinitialize url algorithm, which runs these steps:

  1. If element's url is non-null, its scheme is "blob", and its cannot-be-a-base-URL flag is set, terminate these steps.

  2. Set the url.

To update href, set the element's href content attribute's value to the element's url, serialized.


The href attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null and this element has no href content attribute, return the empty string.

  4. Otherwise, if url is null, return this element's href content attribute's value.

  5. Return url, serialized.

The href attribute's setter must set this element's href content attribute's value to the given value.

The origin attribute's getter must run these steps:

  1. Reinitialize url.

  2. If this element's url is null, return the empty string.

  3. Return the serialization of this element's url's origin.

The protocol attribute's getter must run these steps:

  1. Reinitialize url.

  2. If this element's url is null, return ":".

  3. Return this element's url's scheme, followed by ":".

The protocol attribute's setter must run these steps:

  1. Reinitialize url.

  2. If this element's url is null, terminate these steps.

  3. Basic URL parse the given value, followed by ":", with this element's url as url and scheme start state as state override.

    Because the URL parser ignores multiple consecutive colons, providing a value of "https:" (or even "https::::") is the same as providing a value of "https".

  4. Update href.

The username attribute's getter must run these steps:

  1. Reinitialize url.

  2. If this element's url is null, return the empty string.

  3. Return this element's url's username.

The username attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null or url cannot have a username/password/port, then return.

  4. Set the username, given url and the given value.

  5. Update href.

The password attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null, then return the empty string.

  4. Return url's password.

The password attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null or url cannot have a username/password/port, then return.

  4. Set the password, given url and the given value.

  5. Update href.

The host attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url or url's host is null, return the empty string.

  4. If url's port is null, return url's host, serialized.

  5. Return url's host, serialized, followed by ":" and url's port, serialized.

The host attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null or url's cannot-be-a-base-URL flag is set, terminate these steps.

  4. Basic URL parse the given value, with url as url and host state as state override.

  5. Update href.

The hostname attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url or url's host is null, return the empty string.

  4. Return url's host, serialized.

The hostname attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null or url's cannot-be-a-base-URL flag is set, terminate these steps.

  4. Basic URL parse the given value, with url as url and hostname state as state override.

  5. Update href.

The port attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url or url's port is null, return the empty string.

  4. Return url's port, serialized.

The port attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null or url cannot have a username/password/port, then return.

  4. If the given value is the empty string, then set url's port to null.

  5. Otherwise, basic URL parse the given value, with url as url and port state as state override.

  6. Update href.

The pathname attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null, return the empty string.

  4. If url's cannot-be-a-base-URL flag is set, return the first string in url's path.

  5. If url's path is empty, then return the empty string.

  6. Return "/", followed by the strings in url's path (including empty strings), separated from each other by "/".

The pathname attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null or url's cannot-be-a-base-URL flag is set, terminate these steps.

  4. Set url's path to the empty list.

  5. Basic URL parse the given value, with url as url and path start state as state override.

  6. Update href.

The search attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null, or url's query is either null or the empty string, return the empty string.

  4. Return "?", followed by url's query.

The search attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null, terminate these steps.

  4. If the given value is the empty string, set url's query to null.

  5. Otherwise:

    1. Let input be the given value with a single leading "?" removed, if any.

    2. Set url's query to the empty string.

    3. Basic URL parse input, with url as url and query state as state override, and this element's node document's document's character encoding as encoding override.

  6. Update href.

The hash attribute's getter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null, or url's fragment is either null or the empty string, return the empty string.

  4. Return "#", followed by url's fragment.

The hash attribute's setter must run these steps:

  1. Reinitialize url.

  2. Let url be this element's url.

  3. If url is null, then return.

  4. If the given value is the empty string, set url's fragment to null.

  5. Otherwise:

    1. Let input be the given value with a single leading "#" removed, if any.

    2. Set url's fragment to the empty string.

    3. Basic URL parse input, with url as url and fragment state as state override.

  6. Update href.

An element element cannot navigate if one of the following is true:

This is also used by form submission for the form element. The exception for a elements is for compatibility with web content.

To get an element's noopener, given an a, area, or form element element and a string target, run these steps:

  1. If element's link types include the noopener or noreferrer keyword, then return true.

  2. If element's link types do not include the opener keyword and target is an ASCII case-insensitive match for "_blank", then return true.

  3. Return false.

When a user follows a hyperlink created by an element subject, optionally with a hyperlink suffix, the user agent must run the following steps:

  1. If subject cannot navigate, then return.

  2. Let replace be false.

  3. Let source be subject's node document's browsing context.

  4. Let targetAttributeValue be the empty string.

  5. If subject is an a or area element, then set targetAttributeValue to the result of getting an element's target given subject.

  6. Let noopener be the result of getting an element's noopener with subject and targetAttributeValue.

  7. Let target and windowType be the result of applying the rules for choosing a browsing context given targetAttributeValue, source, and noopener.

  8. If target is null, then return.

  9. Parse the URL given by subject's href attribute, relative to subject's node document.

  10. If that is successful, let URL be the resulting URL string.

    Otherwise, if parsing the URL failed, the user agent may report the error to the user in a user-agent-specific manner, may queue an element task on the DOM manipulation task source given subject to navigate the target browsing context to an error page to report the error, or may ignore the error and do nothing. In any case, the user agent must then return.

  11. If there is a hyperlink suffix, append it to URL.

  12. Let request be a new request whose url is URL and whose referrer policy is the current state of subject's referrerpolicy content attribute.

  13. If subject's link types includes the noreferrer keyword, then set request's referrer to "no-referrer".

  14. Let historyHandling be "replace" if windowType is not "existing or none"; otherwise, "default".

  15. Queue an element task on the DOM manipulation task source given subject to navigate target to request with historyHandling set to historyHandling and the source browsing context set to source.

4.6.5 Downloading resources

HTMLAnchorElement/download

Support in all current engines.

Firefox20+Safari10.1+Chrome15+
Opera15+Edge79+
Edge (Legacy)13+Internet ExplorerNo
Firefox Android20+Safari iOS10.3+Chrome Android18+WebView Android≤37+Samsung Internet1.0+Opera Android14+

In some cases, resources are intended for later use rather than immediate viewing. To indicate that a resource is intended to be downloaded for use later, rather than immediately used, the download attribute can be specified on the a or area element that creates the hyperlink to that resource.

The attribute can furthermore be given a value, to specify the file name that user agents are to use when storing the resource in a file system. This value can be overridden by the `Content-Disposition` HTTP header's filename parameters. [RFC6266]

In cross-origin situations, the download attribute has to be combined with the `Content-Disposition` HTTP header, specifically with the attachment disposition type, to avoid the user being warned of possibly nefarious activity. (This is to protect users from being made to download sensitive personal or confidential information without their full understanding.)


The following allowed to download algorithm takes an initiator browsing context and an instantiator browsing context, and returns a boolean indicating whether or not downloading is allowed:

  1. If the initiator browsing context's sandboxing flags has the sandboxed downloads browsing context flag set, then return false.

  2. If the instantiator browsing context is non-null, and its sandboxing flags has the sandboxed downloads browsing context flag set, then return false.

  3. Optionally, the user agent may return false, if it believes doing so would safeguard the user from a potentially hostile download.

  4. Return true.

When a user downloads a hyperlink created by an element subject, optionally with a hyperlink suffix, the user agent must run the following steps:

  1. If subject cannot navigate, then return.

  2. Run the allowed to download algorithm with the subject's node document's browsing context and null. If the algorithm returns false, then return.

  3. Parse the URL given by subject's href attribute, relative to subject's node document.

  4. If parsing the URL fails, the user agent may report the error to the user in a user-agent-specific manner, may navigate to an error page to report the error, or may ignore the error and do nothing. In either case, the user agent must return.

  5. Otherwise, let URL be the resulting URL string.

  6. If there is a hyperlink suffix, append it to URL.

  7. Run these steps in parallel:

    1. Let request be a new request whose url is URL, client is entry settings object, initiator is "download", destination is the empty string, and whose synchronous flag and use-URL-credentials flag are set.

    2. Handle the result of fetching request as a download.

When a user agent is to handle a resource obtained from a fetch as a download, it should provide the user with a way to save the resource for later use, if a resource is successfully obtained. Otherwise, it should report any problems downloading the file to the user.

If the user agent needs a file name for a resource being handled as a download, it should select one using the following algorithm.

This algorithm is intended to mitigate security dangers involved in downloading files from untrusted sites, and user agents are strongly urged to follow it.

  1. Let filename be the undefined value.

  2. If the resource has a `Content-Disposition` header, that header specifies the attachment disposition type, and the header includes file name information, then let filename have the value specified by the header, and jump to the step labeled sanitize below. [RFC6266]

  3. Let interface origin be the origin of the Document in which the download or navigate action resulting in the download was initiated, if any.

  4. Let resource origin be the origin of the URL of the resource being downloaded, unless that URL's scheme component is data, in which case let resource origin be the same as the interface origin, if any.

  5. If there is no interface origin, then let trusted operation be true. Otherwise, let trusted operation be true if resource origin is the same origin as interface origin, and false otherwise.

  6. If trusted operation is true and the resource has a `Content-Disposition` header and that header includes file name information, then let filename have the value specified by the header, and jump to the step labeled sanitize below. [RFC6266]

  7. If the download was not initiated from a hyperlink created by an a or area element, or if the element of the hyperlink from which it was initiated did not have a download attribute when the download was initiated, or if there was such an attribute but its value when the download was initiated was the empty string, then jump to the step labeled no proposed file name.

  8. Let proposed filename have the value of the download attribute of the element of the hyperlink that initiated the download at the time the download was initiated.

  9. If trusted operation is true, let filename have the value of proposed filename, and jump to the step labeled sanitize below.

  10. If the resource has a `Content-Disposition` header and that header specifies the attachment disposition type, let filename have the value of proposed filename, and jump to the step labeled sanitize below. [RFC6266]

  11. No proposed file name: If trusted operation is true, or if the user indicated a preference for having the resource in question downloaded, let filename have a value derived from the URL of the resource in an implementation-defined manner, and jump to the step labeled sanitize below.

  12. Let filename be set to the user's preferred file name or to a file name selected by the user agent, and jump to the step labeled sanitize below.

    If the algorithm reaches this step, then a download was begun from a different origin than the resource being downloaded, and the origin did not mark the file as suitable for downloading, and the download was not initiated by the user. This could be because a download attribute was used to trigger the download, or because the resource in question is not of a type that the user agent supports.

    This could be dangerous, because, for instance, a hostile server could be trying to get a user to unknowingly download private information and then re-upload it to the hostile server, by tricking the user into thinking the data is from the hostile server.

    Thus, it is in the user's interests that the user be somehow notified that the resource in question comes from quite a different source, and to prevent confusion, any suggested file name from the potentially hostile interface origin should be ignored.

  13. Sanitize: Optionally, allow the user to influence filename. For example, a user agent could prompt the user for a file name, potentially providing the value of filename as determined above as a default value.

  14. Adjust filename to be suitable for the local file system.

    For example, this could involve removing characters that are not legal in file names, or trimming leading and trailing whitespace.

  15. If the platform conventions do not in any way use extensions to determine the types of file on the file system, then return filename as the file name.

  16. Let claimed type be the type given by the resource's Content-Type metadata, if any is known. Let named type be the type given by filename's extension, if any is known. For the purposes of this step, a type is a mapping of a MIME type to an extension.

  17. If named type is consistent with the user's preferences (e.g. because the value of filename was determined by prompting the user), then return filename as the file name.

  18. If claimed type and named type are the same type (i.e. the type given by the resource's Content-Type metadata is consistent with the type given by filename's extension), then return filename as the file name.

  19. If the claimed type is known, then alter filename to add an extension corresponding to claimed type.

    Otherwise, if named type is known to be potentially dangerous (e.g. it will be treated by the platform conventions as a native executable, shell script, HTML application, or executable-macro-capable document) then optionally alter filename to add a known-safe extension (e.g. ".txt").

    This last step would make it impossible to download executables, which might not be desirable. As always, implementers are forced to balance security and usability in this matter.

  20. Return filename as the file name.

For the purposes of this algorithm, a file extension consists of any part of the file name that platform conventions dictate will be used for identifying the type of the file. For example, many operating systems use the part of the file name following the last dot (".") in the file name to determine the type of the file, and from that the manner in which the file is to be opened or executed.

User agents should ignore any directory or path information provided by the resource itself, its URL, and any download attribute, in deciding where to store the resulting file in the user's file system.

If a hyperlink created by an a or area element has a ping attribute, and the user follows the hyperlink, and the value of the element's href attribute can be parsed, relative to the element's node document, without failure, then the user agent must take the ping attribute's value, split that string on ASCII whitespace, parse each resulting token relative to the element's node document, and then run these steps for each resulting URL record ping URL, ignoring tokens that fail to parse:

  1. If ping URL's scheme is not an HTTP(S) scheme, then return.

  2. Optionally, return. (For example, the user agent might wish to ignore any or all ping URLs in accordance with the user's expressed preferences.)

  3. Let request be a new request whose url is ping URL, method is `POST`, body is `PING`, client is the environment settings object of the Document containing the hyperlink, destination is the empty string, credentials mode is "include", referrer is "no-referrer", and whose use-URL-credentials flag is set.

  4. Let target URL be the resulting URL string obtained from parsing the value of the element's href attribute and then:

    If the URL of the Document object containing the hyperlink being audited and ping URL have the same origin
    If the origins are different, but the scheme of the URL of the Document containing the hyperlink being audited is not "https"
    request must include a `Ping-From` header with, as its value, the URL of the document containing the hyperlink, and a `Ping-To` HTTP header with, as its value, the target URL.
    Otherwise
    request must include a `Ping-To` HTTP header with, as its value, target URL. request does not include a `Ping-From` header.
  5. Fetch request.

This may be done in parallel with the primary fetch, and is independent of the result of that fetch.

User agents should allow the user to adjust this behavior, for example in conjunction with a setting that disables the sending of HTTP `Referer` (sic) headers. Based on the user's preferences, UAs may either ignore the ping attribute altogether, or selectively ignore URLs in the list (e.g. ignoring any third-party URLs); this is explicitly accounted for in the steps above.

User agents must ignore any entity bodies returned in the responses. User agents may close the connection prematurely once they start receiving a response body.

When the ping attribute is present, user agents should clearly indicate to the user that following the hyperlink will also cause secondary requests to be sent in the background, possibly including listing the actual target URLs.

For example, a visual user agent could include the hostnames of the target ping URLs along with the hyperlink's actual URL in a status bar or tooltip.

The ping attribute is redundant with pre-existing technologies like HTTP redirects and JavaScript in allowing web pages to track which off-site links are most popular or allowing advertisers to track click-through rates.

However, the ping attribute provides these advantages to the user over those alternatives:

Thus, while it is possible to track users without this feature, authors are encouraged to use the ping attribute so that the user agent can make the user experience more transparent.

4.6.6 Link types

Link_types

Support in all current engines.

Firefox1+SafariYesChrome1+
OperaYesEdge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android4+Safari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes

Link_types

The following table summarizes the link types that are defined by this specification, by their corresponding keywords. This table is non-normative; the actual definitions for the link types are given in the next few sections.

In this section, the term referenced document refers to the resource identified by the element representing the link, and the term current document refers to the resource within which the element representing the link finds itself.

To determine which link types apply to a link, a, area, or form element, the element's rel attribute must be split on ASCII whitespace. The resulting tokens are the keywords for the link types that apply to that element.

Except where otherwise specified, a keyword must not be specified more than once per rel attribute.

Some of the sections that follow the table below list synonyms for certain keywords. The indicated synonyms are to be handled as specified by user agents, but must not be used in documents (for example, the keyword "copyright").

Keywords are always ASCII case-insensitive, and must be compared as such.

Thus, rel="next" is the same as rel="NEXT".

Keywords that are body-ok affect whether link elements are allowed in the body. The body-ok keywords are dns-prefetch, modulepreload, pingback, preconnect, prefetch, preload, prerender, and stylesheet.

New link types that are to be implemented by web browsers are to be added to this standard. The remainder can be registered as extensions.

Link typeEffect on...body-okBrief description
linka and areaform
alternateHyperlinknot allowed · Gives alternate representations of the current document.
canonicalHyperlinknot allowed · Gives the preferred URL for the current document.
authorHyperlinknot allowed · Gives a link to the author of the current document or article.
bookmarknot allowedHyperlinknot allowed · Gives the permalink for the nearest ancestor section.
dns-prefetchExternal Resourcenot allowed Yes Specifies that the user agent should preemptively perform DNS resolution for the target resource's origin.
externalnot allowedAnnotation · Indicates that the referenced document is not part of the same site as the current document.
helpHyperlink · Provides a link to context-sensitive help.
iconExternal Resourcenot allowed · Imports an icon to represent the current document.
manifestExternal Resourcenot allowed · Imports or links to an application manifest. [MANIFEST]
modulepreloadExternal Resourcenot allowed Yes Specifies that the user agent must preemptively fetch the module script and store it in the document's module map for later evaluation. Optionally, the module's dependencies can be fetched as well.
licenseHyperlink · Indicates that the main content of the current document is covered by the copyright license described by the referenced document.
nextHyperlink · Indicates that the current document is a part of a series, and that the next document in the series is the referenced document.
nofollownot allowedAnnotation · Indicates that the current document's original author or publisher does not endorse the referenced document.
noopenernot allowedAnnotation · Creates a top-level browsing context that is not an auxiliary browsing context if the hyperlink would create either of those to begin with (i.e., has an appropriate target attribute value).
noreferrernot allowedAnnotation · No `Referer` (sic) header will be included. Additionally, has the same effect as noopener.
openernot allowedAnnotation · Creates an auxiliary browsing context if the hyperlink would otherwise create a top-level browsing context that is not an auxiliary browsing context (i.e., has "_blank" as target attribute value).
pingbackExternal Resourcenot allowed Yes Gives the address of the pingback server that handles pingbacks to the current document.
preconnectExternal Resourcenot allowed Yes Specifies that the user agent should preemptively connect to the target resource's origin.
prefetchExternal Resourcenot allowed Yes Specifies that the user agent should preemptively fetch and cache the target resource as it is likely to be required for a followup navigation.
preloadExternal Resourcenot allowed Yes Specifies that the user agent must preemptively fetch and cache the target resource for current navigation according to the potential destination given by the as attribute (and the priority associated with the corresponding destination).
prerenderExternal Resourcenot allowed Yes Specifies that the user agent should preemptively fetch the target resource and process it in a way that helps deliver a faster response in the future.
prevHyperlink · Indicates that the current document is a part of a series, and that the previous document in the series is the referenced document.
searchHyperlink · Gives a link to a resource that can be used to search through the current document and its related pages.
stylesheetExternal Resourcenot allowed Yes Imports a style sheet.
tagnot allowedHyperlinknot allowed · Gives a tag (identified by the given address) that applies to the current document.
4.6.6.1 Link type "alternate"

Alternative_style_sheets

Support in one engine only.

Firefox3+Safari?Chrome1–48
OperaYesEdgeNo
Edge (Legacy)?Internet Explorer8+
Firefox Android4+Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

alternate 关键字可用于 link, aarea 元素。

该关键的含义取决于其他属性的值。

如果是一个 link 元素且 rel 属性包含关键字 stylesheet

alternate 关键字会更改 stylesheet 关键字的含义(见它的说明)。 alternate 关键字自己不会创建链接。

下面的这些 link 元素提供了一些样式表:

<!-- a persistent style sheet -->
<link rel="stylesheet" href="default.css">

<!-- the preferred alternate style sheet -->
<link rel="stylesheet" href="green.css" title="Green styles">

<!-- some alternate style sheets -->
<link rel="alternate stylesheet" href="contrast.css" title="High contrast">
<link rel="alternate stylesheet" href="big.css" title="Big fonts">
<link rel="alternate stylesheet" href="wide.css" title="Wide screen">
如果 alternate 关键字用于 type 属性值为 application/rss+xmlapplication/atom+xml

该关键字创建了一个 超链接 指向聚合 feed(不一定需要发布和当前页面同样的内容)。

为了 feed 自动发现,用户代理应该考虑文档里所有使用了 alternate 关键字, 并且 type 属性值为 application/rss+xmlapplication/atom+xmllink 元素。 如果用户代理有默认 feed 聚合的概念,应该默认使用(按照树序)第一个这样的元素。

下面的 link 元素给出了一个博客的 feed 聚合:

<link rel="alternate" type="application/atom+xml" href="posts.xml" title="Cool Stuff Blog">
<link rel="alternate" type="application/atom+xml" href="posts.xml?category=robots" title="Cool Stuff Blog: robots category">
<link rel="alternate" type="application/atom+xml" href="comments.xml" title="Cool Stuff Blog: Comments">

这样的 link 元素应该用于用户代理自动发现 feed,且第一个(如果可用的话)为默认值。

下面的例子使用 a 元素给用户提供了多种不同的 feed 聚合:

<p>You can access the planets database using Atom feeds:</p>
<ul>
 <li><a href="recently-visited-planets.xml" rel="alternate" type="application/atom+xml">Recently Visited Planets</a></li>
 <li><a href="known-bad-planets.xml" rel="alternate" type="application/atom+xml">Known Bad Planets</a></li>
 <li><a href="unexplored-planets.xml" rel="alternate" type="application/atom+xml">Unexplored Planets</a></li>
</ul>

这些链接不会被用于 feed 自动发现。

否则

该关键字将创建一个 超链接 指向当前文档的另一种表示。

被引用文档的特征由 hreflangtype 属性给出。

如果 alternate 关键字和 hreflang 属性一起使用, 且该属性的值与 文档元素语言 不同, 它表示被引用文档是一个翻译版本。

如果 alternate 关键字和 type 属性一起使用,它表示被引用文档是当前文档的另一种格式的版本。

hreflangtype 属性可以和 alternate 关键字一起使用。

下面的例子展示了如何指定当前页面的其他格式版本,其他语言版本,以及为其他媒体准备的版本:

<link rel=alternate href="/en/html" hreflang=en type=text/html title="English HTML">
<link rel=alternate href="/fr/html" hreflang=fr type=text/html title="French HTML">
<link rel=alternate href="/en/html/print" hreflang=en type=text/html media=print title="English HTML (for printing)">
<link rel=alternate href="/fr/html/print" hreflang=fr type=text/html media=print title="French HTML (for printing)">
<link rel=alternate href="/en/pdf" hreflang=en type=application/pdf title="English PDF">
<link rel=alternate href="/fr/pdf" hreflang=fr type=application/pdf title="French PDF">

这一关系具有传递性 — 也就是说如果一篇文档使用 "alternate" 链接到另外两篇文档, 那么意味着那两篇文档是第一篇文档的替代表示,也意味着那两篇文档互相为替代表示。

author 关键字可用于 linkaarea 元素。该关键字会创建一个 超链接

对于 aarea 元素,author 关键字表示被引用的文档提供了离定义该超链接的元素最近的祖先 article 元素的作者的更多信息, 如果没有这样的祖先元素,就是指整个页面的作者。

对于 link 元素,author 关键字表示被引用文档提供了 关于整个页面的作者的更多信息。

"被引用文档" 可以是(也经常是)一个 mailto: URL 给出了作者的 e-mail 地址。[MAILTO]

同义词:由于历史原因,用户代理必须把 rev 属性值为 "made" 的 link, a, 和 area 元素也当作有一个 author 关键字来处理。

bookmark 关键字可用于 linkaarea 元素。该关键字会创建一个 超链接

bookmark 关键字给出了这个链接元素最近的祖先 article 元素的永久链接。如果没有祖先 article 元素的话,就是指 这个链接元素关联最紧密的 section

下面的片段有三个永久链接。用户代理通过给出永久链接的位置来确定每个部分对应的永久链接。

 ...
 <body>
  <h1>Example of permalinks</h1>
  <div id="a">
   <h2>First example</h2>
   <p><a href="a.html" rel="bookmark">This permalink applies to
   only the content from the first H2 to the second H2</a>. The DIV isn't
   exactly that section, but it roughly corresponds to it.</p>
  </div>
  <h2>Second example</h2>
  <article id="b">
   <p><a href="b.html" rel="bookmark">This permalink applies to
   the outer ARTICLE element</a> (which could be, e.g., a blog post).</p>
   <article id="c">
    <p><a href="c.html" rel="bookmark">This permalink applies to
    the inner ARTICLE element</a> (which could be, e.g., a blog comment).</p>
   </article>
  </article>
 </body>
 ...

The canonical keyword may be used with link element. This keyword creates a hyperlink.

The canonical keyword indicates that URL given by the href attribute is the preferred URL for the current document. That helps search engines reduce duplicate content, as described in more detail in The Canonical Link Relation. [RFC6596]

Link_types/dns-prefetch

Firefox3+Safari?Chrome46+
Opera33+Edge79+
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView Android46+Samsung InternetYesOpera Android?

dns-prefetch 关键字可用于 link 元素。该关键字会创建 外部资源链接。 这个关键字是 body-ok 的。

dns-prefetch 关键字表示最好为指定资源的 事先执行 DNS 解析,因为用户很可能会要位于那个 的资源,避免了 DNS 解析相关的延迟会提升用户体验。 用户代理必须实现 Resource Hints 所描述的 dns-prefetch 关键字的处理模型。 [RESOURCEHINTS]

dns-prefetch 关键字没有默认的资源类型。

external 关键字可用于 aarea 元素。该元素不会创建 超链接,但可以 注释 该元素创建的任何其他超链接 (如果其他关键字没有创建超链接的话就是注释暗示的超链接)。

external 关键字表示该链接指向的文档不是当前文档所属站点的一部分。

help 关键字可用于 linkaarea 元素。该关键字会创建一个 超链接

对于 aarea 元素,help 关键字表示被引用文档为定义了该超链接的父元素及其子元素提供了更多帮助信息。

在下面的例子中,表单控件关联了上下文相关的帮助。用户代理可以使用这个信息, 比如用户按下 “Help” 或 “F1” 键时可以显示被引用的文档。

 <p><label> Topic: <input name=topic> <a href="help/topic.html" rel="help">(Help)</a></label></p>

对于 link 元素,这个 help 关键字表示 被引用的文档为整个页面提供了帮助。

对于 aarea 元素,在有些浏览器中 help 关键字会使链接显示不同的光标。

4.6.6.8 Link type "icon"

Link_types#icon

Support in all current engines.

Firefox2+Safari3.1+Chrome4+
Opera9+Edge79+
Edge (Legacy)12+Internet Explorer11
Firefox Android4+Safari iOSNoChrome Android18+WebView Android38+Samsung Internet4.0+Opera AndroidNo
caniuse.com table

The icon keyword may be used with link elements. This keyword creates an external resource link.

The specified resource is an icon representing the page or site, and should be used by the user agent when representing the page in the user interface.

Icons could be auditory icons, visual icons, or other kinds of icons. If multiple icons are provided, the user agent must select the most appropriate icon according to the type, media, and sizes attributes. If there are multiple equally appropriate icons, user agents must use the last one declared in tree order at the time that the user agent collected the list of icons. If the user agent tries to use an icon but that icon is determined, upon closer examination, to in fact be inappropriate (e.g. because it uses an unsupported format), then the user agent must try the next-most-appropriate icon as determined by the attributes.

User agents are not required to update icons when the list of icons changes, but are encouraged to do so.

There is no default type for resources given by the icon keyword. However, for the purposes of determining the type of the resource, user agents must expect the resource to be an image.

The sizes keywords represent icon sizes in raw pixels (as opposed to CSS pixels).

An icon that is 50 CSS pixels wide intended for displays with a device pixel density of two device pixels per CSS pixel (2x, 192dpi) would have a width of 100 raw pixels. This feature does not support indicating that a different resource is to be used for small high-resolution icons vs large low-resolution icons (e.g. 50×50 2x vs 100×100 1x).

To parse and process the attribute's value, the user agent must first split the attribute's value on ASCII whitespace, and must then parse each resulting keyword to determine what it represents.

The any keyword represents that the resource contains a scalable icon, e.g. as provided by an SVG image.

Other keywords must be further parsed as follows to determine what they represent:

The keywords specified on the sizes attribute must not represent icon sizes that are not actually available in the linked resource.

The linked resource fetch setup steps for this type of linked resource, given a link element el and request request, are:

  1. Set request's destination to "image".

  2. Return true.

In the absence of a link with the icon keyword, for Document objects whose URL's scheme is an HTTP(S) scheme, user agents may instead run these steps in parallel:

  1. Let request be a new request whose url is the URL record obtained by resolving the URL "/favicon.ico" against the Document object's URL, client is the Document object's relevant settings object, destination is "image", synchronous flag is set, credentials mode is "include", and whose use-URL-credentials flag is set.

  2. Let response be the result of fetching request.

  3. Use response's unsafe response as an icon as if it had been declared using the icon keyword.

The following snippet shows the top part of an application with several icons.

<!DOCTYPE HTML>
<html lang="en">
 <head>
  <title>lsForums — Inbox</title>
  <link rel=icon href=favicon.png sizes="16x16" type="image/png">
  <link rel=icon href=windows.ico sizes="32x32 48x48" type="image/vnd.microsoft.icon">
  <link rel=icon href=mac.icns sizes="128x128 512x512 8192x8192 32768x32768">
  <link rel=icon href=iphone.png sizes="57x57" type="image/png">
  <link rel=icon href=gnome.svg sizes="any" type="image/svg+xml">
  <link rel=stylesheet href=lsforums.css>
  <script src=lsforums.js></script>
  <meta name=application-name content="lsForums">
 </head>
 <body>
  ...

For historical reasons, the icon keyword may be preceded by the keyword "shortcut". If the "shortcut" keyword is present, the rel attribute's entire value must be an ASCII case-insensitive match for the string "shortcut icon" (with a single U+0020 SPACE character between the tokens and no other ASCII whitespace).

license 关键字可用于 linkaarea 元素。该关键字会创建一个 超链接

license 关键字表示被引用文档提供了当前文档中主要内容的版权许可条款。

本规范未指定如何区分文档中的主要内容和不被视为该主要内容的部分。 应该让用户能够明确这个区分。

考虑一个相片分享网站。这个站点的一个页面可能会描述并显示一张照片,这个页面可能是这样写的:

<!DOCTYPE HTML>
<html lang="en">
 <head>
  <title>Exampl Pictures: Kissat</title>
  <link rel="stylesheet" href="/style/default">
 </head>
 <body>
  <h1>Kissat</h1>
  <nav>
   <a href="../">Return to photo index</a>
  </nav>
  <figure>
   <img src="/pix/39627052_fd8dcd98b5.jpg">
   <figcaption>Kissat</figcaption>
  </figure>
  <p>One of them has six toes!</p>
  <p><small><a rel="license" href="http://www.opensource.org/licenses/mit-license.php">MIT Licensed</a></small></p>
  <footer>
   <a href="/">Home</a> | <a href="../">Photo index</a>
   <p><small>© copyright 2009 Exampl Pictures. All Rights Reserved.</small></p>
  </footer>
 </body>
</html>

这个例子中 license 只适用于这张照片 (该文档的主要内容)而不是整个文档。尤其不是页面的设计本身,它的版权在文档底部给出。 这可以通过样式来表达清楚(例如让许可链接贴着照片,同时把页面的版权以细小的文字放在页底)。

同义词:由于历史原因,用户代理必须把 "copyright" 当作 license 关键字处理。

Link_types/manifest

Support in one engine only.

Firefox?Safari?ChromeNo
OperaNoEdgeNo
Edge (Legacy)NoInternet Explorer?
Firefox Android?Safari iOS?Chrome Android39+WebView Android39+Samsung Internet4.0+Opera Android?

The manifest keyword may be used with link elements. This keyword creates an external resource link.

The manifest keyword indicates the manifest file that provides metadata associated with the current document.

There is no default type for resources given by the manifest keyword.

The appropriate time to fetch and process the linked resource for this link type is when the user agent deems it necessary. For example, when the user chooses to install the web application. In that case, only the first link element in tree order whose rel attribute contains the token manifest may be used.

A user agent must not delay the load event for this link type.

The linked resource fetch setup steps for this type of linked resource, given a link element el and request request, are:

  1. Let context be el's node document's browsing context.

  2. If context is null, then return false.

  3. If context is not a top-level browsing context, then return false.

  4. Set request's initiator to "manifest".

  5. Set request's destination to "manifest".

  6. Set request's mode to "cors".

  7. Set request's credentials mode to the CORS settings attribute credentials mode for el's crossorigin content attribute.

  8. Return true.

To process this type of linked resource given a link element el, boolean success, and response response:

  1. If response's Content-Type metadata is not a JSON MIME type, then set success to false.

  2. If success is true, then process the manifest given el and response. [MANIFEST]

Link_types/modulepreload

Support in one engine only.

Firefox?Safari?Chrome66+
Opera53+Edge79+
Edge (Legacy)NoInternet Explorer?
Firefox Android?Safari iOS?Chrome Android66+WebView Android66+Samsung Internet9.0+Opera Android47+

The modulepreload keyword may be used with link elements. This keyword creates an external resource link. This keyword is body-ok.

The modulepreload keyword is a specialized alternative to the preload keyword, with a processing model geared toward preloading module scripts. In particular, it uses the specific fetch behavior for module scripts (including, e.g., a different interpretation of the crossorigin attribute), and places the result into the appropriate module map for later evaluation. In contrast, a similar external resource link using the preload keyword would place the result in the preload cache, without affecting the document's module map.

Additionally, implementations can take advantage of the fact that module scripts declare their dependencies in order to fetch the specified module's dependency as well. This is intended as an optimization opportunity, since the user agent knows that, in all likelihood, those dependencies will also be needed later. It will not generally be observable without using technology such as service workers, or monitoring on the server side. Notably, the appropriate load or error events will occur after the specified module is fetched, and will not wait for any dependencies.

The appropriate times to fetch and process the linked resource for such a link are:

Unlike some other link relations, changing the relevant attributes (such as as, crossorigin, and referrerpolicy) of such a link does not trigger a new fetch. This is because the document's module map has already been populated by a previous fetch, and so re-fetching would be pointless.

The fetch and process the linked resource algorithm for modulepreload links, given a link element el, is as follows:

  1. If the href attribute's value is the empty string, then return.

  2. Let destination be the current state of the as attribute (a destination), or "script" if it is in no state.

  3. If destination is not script-like, then queue an element task on the networking task source given the link element to fire an event named error at the link element, and return.

  4. Parse the URL given by the href attribute, relative to the element's node document. If that fails, then return. Otherwise, let url be the resulting URL record.

  5. Let settings object be the link element's node document's relevant settings object.

  6. Let credentials mode be the CORS settings attribute credentials mode for the crossorigin attribute.

  7. Let cryptographic nonce be the current value of the element's [[CryptographicNonce]] internal slot.

  8. Let integrity metadata be the value of the integrity attribute, if it is specified, or the empty string otherwise.

  9. Let referrer policy be the current state of the element's referrerpolicy attribute.

  10. Let options be a script fetch options whose cryptographic nonce is cryptographic nonce, integrity metadata is integrity metadata, parser metadata is "not-parser-inserted", credentials mode is credentials mode, and referrer policy is referrer policy.

  11. Fetch a modulepreload module script graph given url, destination, settings object, and options. Wait until the algorithm asynchronously completes with result.

  12. If result is null, then fire an event named error at the link element, and return.

  13. Fire an event named load at the link element.

The following snippet shows the top part of an application with several modules preloaded:

<!DOCTYPE html>
<html lang="en">
<title>IRCFog</title>

<link rel="modulepreload" href="app.mjs">
<link rel="modulepreload" href="helpers.mjs">
<link rel="modulepreload" href="irc.mjs">
<link rel="modulepreload" href="fog-machine.mjs">

<script type="module" src="app.mjs">
...

Assume that the module graph for the application is as follows:

The module graph is rooted at app.mjs, which depends on irc.mjs and fog-machine.mjs. In turn, irc.mjs depends on helpers.mjs.

Here we see the application developer has used modulepreload to declare all of the modules in their module graph, ensuring that the user agent initiates fetches for them all. Without such preloading, the user agent might need to go through multiple network roundtrips before discovering helpers.mjs, if technologies such as HTTP/2 Server Push are not in play. In this way, modulepreload link elements can be used as a sort of "manifest" of the application's modules.

The following code shows how modulepreload links can be used in conjunction with import() to ensure network fetching is done ahead of time, so that when import() is called, the module is already ready (but not evaluated) in the module map:

<link rel="modulepreload" href="awesome-viewer.mjs">

<button onclick="import('./awesome-viewer.mjs').then(m => m.view())">
  View awesome thing
</button>

nofollow 关键字可用于 aarea 元素。这个关键字不会创建 超链接,但是可以 注释 任何其他该元素创建的超链接。 (如果没有其他关键字创建链接,那就注释其隐含的超链接)。

nofollow 关键字表示该链接不被该网页的原始作者或发布者所认可, 或者这个指向被引用文档的链接主要是为了这两个页面的所有者之间的商业关系。

Link_types/noopener

Support in all current engines.

Firefox52+Safari10.1+Chrome49+
Opera36+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android52+Safari iOS10.3+Chrome Android49+WebView Android49+Samsung Internet5.0+Opera Android36+

Link_types/noopener

Support in all current engines.

Firefox52+Safari10.1+Chrome49+
Opera36+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android52+Safari iOS10.3+Chrome Android49+WebView Android49+Samsung Internet5.0+Opera Android36+

The noopener keyword may be used with a, area, and form elements. This keyword does not create a hyperlink, but annotates any other hyperlinks created by the element (the implied hyperlink, if no other keywords create one).

The keyword indicates that any newly created top-level browsing context which results from following the hyperlink will not be an auxiliary browsing context. E.g., its window.opener attribute will be null.

See also the processing model where the branching between an auxiliary browsing context and a top-level browsing context is defined.

This typically creates an auxiliary browsing context (assuming there is no existing browsing context whose browsing context name is "example"):

<a href=help.html target=example>Help!</a>

This creates a top-level browsing context that is not an auxiliary browsing context (assuming the same thing):

<a href=help.html target=example rel=noopener>Help!</a>

These are equivalent and only navigate the parent browsing context:

<a href=index.html target=_parent>Home</a>
<a href=index.html target=_parent rel=noopener>Home</a>

Link_types/noreferrer

Support in all current engines.

Firefox33+Safari5+Chrome16+
Opera15+Edge79+
Edge (Legacy)13+Internet Explorer🔰 11
Firefox Android33+Safari iOS4.3+Chrome Android18+WebView Android3+Samsung Internet1.5+Opera Android14+

Link_types/noreferrer

Support in all current engines.

Firefox33+Safari5+Chrome16+
Opera15+Edge79+
Edge (Legacy)13+Internet Explorer🔰 11
Firefox Android33+Safari iOS4.3+Chrome Android18+WebView Android3+Samsung Internet1.5+Opera Android14+

The noreferrer keyword may be used with a, area, and form elements. This keyword does not create a hyperlink, but annotates any other hyperlinks created by the element (the implied hyperlink, if no other keywords create one).

It indicates that no referrer information is to be leaked when following the link and also implies the noopener keyword behavior under the same conditions.

See also the processing model where referrer is directly manipulated.

<a href="..." rel="noreferrer" target="_blank"> has the same behavior as <a href="..." rel="noreferrer noopener" target="_blank">.

The opener keyword may be used with a, area, and form elements. This keyword does not create a hyperlink, but annotates any other hyperlinks created by the element (the implied hyperlink, if no other keywords create one).

The keyword indicates that any newly created top-level browsing context which results from following the hyperlink will be an auxiliary browsing context.

See also the processing model.

In the following example the opener is used to allow the help page popup to navigate its opener, e.g., in case what the user is looking for can be found elsewhere. An alternative might be to use a named target, rather than _blank, but this has the potential to clash with existing names.

<a href="..." rel=opener target=_blank>Help!</a>

pingback 关键字可以用于 link 元素。该关键字会创建一个 外部资源链接。 这个关键字是 body-ok 的。

关于 pingback 关键字的语义,参考 Pingback 1.0 规范。 [PINGBACK]

Link_types/preconnect

Support in all current engines.

Firefox39+Safari11.1+Chrome46+
Opera33+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android39+Safari iOS11.3+Chrome Android46+WebView Android46+Samsung Internet4.0+Opera Android33+

preconnect 关键字可用于 link 元素。 该关键字会创建一个 外部资源链接。 这个关键字是 body-ok 的。

preconnect 关键字表示最好事先初始化一个到指定资源的 的连接。因为用户很可能会访问处于这个 的资源,这省去了建立连接的延迟,所以会提升用户体验。 用户代理必须实现 Resource Hints 中描述的 preconnect 关键字的处理模型。 [RESOURCEHINTS]

preconnect 关键字给出的资源没有默认类型。

Link_types/prefetch

Firefox2+SafariNoChrome8+
Opera15+Edge79+
Edge (Legacy)12+Internet Explorer11
Firefox Android4+Safari iOSNoChrome Android18+WebView Android4.4+Samsung Internet1.5+Opera Android14+

prefetch 关键字可用于 link 元素。该关键字会创建 外部资源链接。 这个关键在是 body-ok 的。

prefetch 关键字表示最好事先 获取 并缓存指定的资源。 因为用户在将来的导航中很可能会要这个资源。 用户代理必须实现 Resource Hints 所描述的 prefetch 关键字的处理模型。 [RESOURCEHINTS]

prefetch 关键字没有默认的资源类型。

Link_types/preload

Support in one engine only.

Firefox85+Safari?Chrome🔰 50+
Opera37+Edge🔰 79+
Edge (Legacy)NoInternet Explorer?
Firefox Android85+Safari iOS?Chrome Android🔰 50+WebView Android50+Samsung Internet5.0+Opera Android?

The preload keyword may be used with link elements. This keyword creates an external resource link. This keyword is body-ok.

The preload keyword indicates that the user agent must preemptively fetch and cache the specified resource according to the potential destination given by the as attribute (and the priority associated with the corresponding destination), as it is highly likely that the user will require this resource for the current navigation. User agents must implement the processing model of the preload keyword described in Preload, as well as in this specification's fetch and process the linked resource algorithm. [PRELOAD]

There is no default type for resources given by the preload keyword.

The linked resource fetch setup steps for this type of linked resource, given a link element el and request request, are:

  1. Let as be the current state of el's as attribute.

  2. If as does not represent a state, return false.

  3. Set request's destination to the result of translating as.

  4. If as is "image", then:

    1. Let selected source and selected pixel density be the URL and pixel density that results from selecting an image source given el, respectively.

    2. If selected source is null, then return false.

    3. Parse selected source, relative to el's node document. If that fails, then return false. Otherwise, let url be the resulting URL record.

    4. Set request's url to url.

  5. Return true.

Link_types/prerender

Support in one engine only.

FirefoxNoSafariNoChrome13+
Opera15+Edge79+
Edge (Legacy)NoInternet Explorer11
Firefox AndroidNoSafari iOSNoChrome Android18+WebView Android4.4+Samsung Internet1.5+Opera Android14+

prerender 关键字可用于 link 元素。该关键字会创建 外部资源链接。 这个关键在是 body-ok 的。

prerender 关键字表示指定的资源可能在下次导航时用到。 所以最好先去 获取 这个资源并处理它, 比如 获取 它的子资源或执行一些渲染。用户代理必须实现 Resource Hints 中描述的 prerender 关键字的处理模型。 [RESOURCEHINTS]

prerender 关键字没有默认的资源类型。

The search keyword may be used with link, a, area, and form elements. This keyword creates a hyperlink.

The search keyword indicates that the referenced document provides an interface specifically for searching the document and its related resources.

OpenSearch description documents can be used with link elements and the search link type to enable user agents to autodiscover search interfaces. [OPENSEARCH]

The stylesheet keyword may be used with link elements. This keyword creates an external resource link that contributes to the styling processing model. This keyword is body-ok.

The specified resource is a CSS style sheet that describes how to present the document.

If the alternate keyword is also specified on the link element, then the link is an alternative style sheet; in this case, the title attribute must be specified on the link element, with a non-empty value.

The default type for resources given by the stylesheet keyword is text/css.

The appropriate times to fetch and process this type of link are:

Quirk: If the document has been set to quirks mode, has the same origin as the URL of the external resource, and the Content-Type metadata of the external resource is not a supported style sheet type, the user agent must instead assume it to be text/css.

The linked resource fetch setup steps for this type of linked resource, given a link element el (ignoring the request) are:

  1. If el's disabled attribute is set, then return false.

  2. If el contributes a script-blocking style sheet, increment el's node document's script-blocking style sheet counter by 1.

  3. Return true.

See issue #968 for plans to use the CSSOM fetch a CSS style sheet algorithm instead of the default fetch and process the linked resource algorithm.

To process this type of linked resource given a link element el, boolean success, and response response, the user agent must run these steps:

  1. If the resource's Content-Type metadata is not text/css, then set success to false.

  2. If el no longer creates an external resource link that contributes to the styling processing model, or if, since the resource in question was fetched, it has become appropriate to fetch it again, then return.

  3. If el has an associated CSS style sheet, remove the CSS style sheet.

  4. If success is true, then:

    1. Create a CSS style sheet with the following properties:

      type

      text/css

      location

      The resulting URL string determined during the fetch and process the linked resource algorithm.

      This is before any redirects get applied.

      owner node

      element

      media

      The media attribute of element.

      This is a reference to the (possibly absent at this time) attribute, rather than a copy of the attribute's current value. CSSOM defines what happens when the attribute is dynamically set, changed, or removed.

      title

      The title attribute of element, if element is in a document tree, or the empty string otherwise.

      This is similarly a reference to the attribute, rather than a copy of the attribute's current value.

      alternate flag

      Set if the link is an alternative style sheet and element's explicitly enabled is false; unset otherwise.

      origin-clean flag

      Set if the resource is CORS-same-origin; unset otherwise.

      parent CSS style sheet
      owner CSS rule

      null

      disabled flag

      Left at its default value.

      CSS rules

      Left uninitialized.

      This doesn't seem right. Presumably we should be using the response body? Tracked as issue #2997.

      The CSS environment encoding is the result of running the following steps: [CSSSYNTAX]

      1. If the element has a charset attribute, get an encoding from that attribute's value. If that succeeds, return the resulting encoding. [ENCODING]

      2. Otherwise, return the document's character encoding. [DOM]

    2. Fire an event named load at el.

  5. Otherwise, fire an event named error at el.

  6. If el contributes a script-blocking style sheet, then:

    1. Assert: el's node document's script-blocking style sheet counter is greater than 0.

    2. Decrement el's node document's script-blocking style sheet counter by 1.

tag 关键字可用于 aarea 元素。该关键字会创建一个 超链接

tag 关键字表示被引用的文档表示的 tag 适用于当前文档。

由于它表示该 tag 适用于当前文档, 在 tag 云 的标记中用这个关键字是不合适的,因为 tag 云列出了很多页面的 tag。

本文档是关于宝石的,所以它有一个 "https://en.wikipedia.org/wiki/Gemstone" tag 来把它归类到“珠宝”,而不是美国的城镇、Ruby 包格式,或瑞士机车分级:

<!DOCTYPE HTML>
<html lang="en">
 <head>
  <title>My Precious</title>
 </head>
 <body>
  <header><h1>My precious</h1> <p>Summer 2012</p></header>
  <p>Recently I managed to dispose of a red gem that had been
  bothering me. I now have a much nicer blue sapphire.</p>
  <p>The red gem had been found in a bauxite stone while I was digging
  out the office level, but nobody was willing to haul it away. The
  same red gem stayed there for literally years.</p>
  <footer>
   Tags: <a rel=tag href="https://en.wikipedia.org/wiki/Gemstone">Gemstone</a>
  </footer>
 </body>
</html>

文档中有两篇文章。但 "tag" 链接适用于整个页面 (不论它放在了哪里,以及是否在 article 元素中)。

<!DOCTYPE HTML>
<html lang="en">
 <head>
  <title>Gem 4/4</title>
 </head>
 <body>
  <article>
   <h1>801: Steinbock</h1>
   <p>The number 801 Gem 4/4 electro-diesel has an ibex and was rebuilt in 2002.</p>
  </article>
  <article>
   <h1>802: Murmeltier</h1>
   <figure>
    <img src="https://upload.wikimedia.org/wikipedia/commons/b/b0/Trains_de_la_Bernina_en_hiver_2.jpg"
         alt="The 802 was red with pantographs and tall vents on the side.">
    <figcaption>The 802 in the 1980s, above Lago Bianco.</figcaption>
   </figure>
   <p>The number 802 Gem 4/4 electro-diesel has a marmot and was rebuilt in 2003.</p>
  </article>
  <p class="topic"><a rel=tag href="https://en.wikipedia.org/wiki/Rhaetian_Railway_Gem_4/4">Gem 4/4</a></p>
 </body>
</html>

有些文档会组成一个文档序列。

文档序列是指,每个文档可以有一个 前驱 和一个 后继。 没有前驱的文档是其所在序列的开始文档, 没有后继的文档是其所在序列的结束文档。

一个文档可能属于多个序列。

next 关键字可用于 link, aarea 元素。该关键字会创建 超链接

next 关键字表示该文档是一个文档序列的一部分, 而且该链接指向逻辑上位于当前文档之后的那个文档。

next 关键字用于 link 元素时, 用户代理应该实现一个 Resource Hints 中描述的处理模型, 也就是说这样的链接应该被当做使用了 dns-prefetch, preconnect, prefetchprerender 关键字来处理。用户代理希望使用哪个资源暗示是实现相关的; 例如用户代理为了节省数据、电池或计算量可能会希望使用代价较小的 preconnect 暗示, 或者希望基于对类似场景中以前的用户行为的启发式分析来选取一个资源暗示。[RESOURCEHINTS]

prev 关键字可用于 link, aarea 元素。该关键字会创建 超链接

prev 关键字表示该文档是一个文档序列的一部分, 而且该链接指向逻辑上位于当前文档之前的那个文档。

同义词:由于历史原因,用户代理必须把 "previous" 关键字当作 prev 关键字处理。

预定义链接类型的扩展 可以注册在 microformats Wiki 已有的 rel 值页面[MFREL]

任何人在任何时候都可以编辑 microformats Wiki 已有的 rel 值页面 来增加一个类型。扩展类型必须指定以下信息:

关键字

要定义的实际关键字。这个值不应与其他已定义的值相似以避免混淆。 (例如只有大小写不同)

如果值包含 U+003A COLON 字符(:),它就必须是一个 绝对 URL

作用于... link

下面之一:

不允许
该关键字不得在 link 元素上指定。
超链接
该关键字可以在 link 元素上指定;它会创建一个 超链接
外部资源
该关键字可以在 link 元素上指定,它会创建一个 外部资源链接
作用于... aarea

下面之一:

不允许
该关键字不得在 aarea 元素上指定。
超链接
该关键字可以在 aarea 元素上指定;它会创建一个 超链接
外部资源
该关键字可以在 aarea 元素上指定;它会创建一个 外部资源链接
超链接注释
该关键字可以在 aarea 元素上指定;它用来 注释 该元素创建的其他 超链接
简要描述

对这个关键字的含义进行简短的非形式化的描述。

规范

指向对该关键字的语义和要求的更细节的描述的链接。 它可以是 Wiki 上的另一个页面,或者一个外部页面。

同义词

有着同样处理要求的其他关键字值的列表。 作者不应该使用已经定义为同义词的值,它们只是为了让用户代理支持旧的内容。 任何人都可以移除一个实践中已经不再使用的同义词 只有用于兼容旧内容的同义词才应该注册在这里。

状态

以下之一:

已提出
该名称还没有接受广泛的 peer review 和 approval。有人提出了它并且正在用或者马上就要使用。
已批准
该名称已经接受了广泛的 peer review 和 approval。并且有一个标准明确地定义了如何处理使用了这个名称的页面,包括哪些使用方式是错误的。
已终止
该名称已经接受了广泛的peer review 并且被认为是有用的。现存的页面已经在使用这个名称, 但新的页面应该避免使用。 "简要说明" 和 "规范" 入口会给出作者应该用哪些替代品,如果有的话。

如果一个关键字与其他现存的值冗余,那么应该把它移除并列为那个现存值的同义词。

如果一个关键字已经添加到 “已提议” 状态经过一个多月的时间并未被使用或标准化, 那么应该把它从注册中移除。

如果一个关键字已经添加到 “已提议” 状态但却与现存的值冗余, 就应该把它移除并列为该现存值的同义词。 如果一个名称被添加到 “已提议” 状态但被发现有害,则应该把它改为 “已终止” 状态。

任何人都可以随时更新状态,但应该根据上述定义进行。

一致性检查工具必须使用 microformats wiki 已有的 rel 值页面 给出的信息来决定值是否被允许: 对于本规范中定义的值或标记为 “已提议” 或 “已批准” 的值,当用于 “作用于...” 字段描述的元素时, 工具必须接受它,但标记为 “已终止” 的值,或者本标准和上述页面都没有列出的值,就必须视为不合法并拒绝它。 一致性检查工具可以缓存这个信息(例如,为了性能原因或为了避免使用不可靠的网络连接)。

当作者使用本规范和 Wiki 页面没有定义的新类型时,一致性检查工具应该可以提示把这个值添加到 Wiki, 使用上面描述的细节,并设为 “已提议” 状态。

microformats wiki 已有 rel 值页面 中定义为扩展的类型, 如果状态是 “已提议” 或 “已批准” 就可以根据 “作用于...” 字段用于 linkrel 属性, a, 和 area 元素。[MFREL]