Html link element attributes

This element includes the global attributes. as This attribute is only used when rel=»preload» has been sent on the element. It specifies the type of content being loaded by the , which is necessary for content prioritization, request matching, application of correct content security policy, and setting of correct Accept request header. charset This attribute defines the character encoding of the linked resource. The value is a space- and/or comma-delimited list of character sets as defined in RFC 2045. The default value is iso-8859-1 .

Usage note: This attribute is obsolete and must not be used by authors. To achieve its effect, use the Content-Type HTTP header on the linked resource.

href This attribute specifies the URL of the linked resource. A URL might be absolute or relative. hreflang This attribute indicates the language of the linked resource. It is purely advisory. Allowed values are determined by BCP47. Use this attribute only if the href attribute is present. integrity Contains inline metadata, a base64-encoded cryptographic hash of a resource (file) you’re telling the browser to fetch, that a user agent can use to verify that a fetched resource has been delivered free of unexpected manipulation. See Subresource Integrity. media This attribute specifies the media which the linked resource applies to. Its value must be a media query. This attribute is mainly useful when linking to external stylesheets by allowing the user agent to pick the best adapted one for the device it runs on.

  • In HTML 4, this can only be a simple white-space-separated list of media description literals, i.e., media types and groups, where defined and allowed as values for this attribute, such as print , screen , aural , braille . HTML5 extended this to any kind of media queries, which are a superset of the allowed values of HTML 4.
  • Browsers not supporting the CSS3 Media Queries won’t necessarily recognize the adequate link; do not forget to set fallback links, the restricted set of media queries defined in HTML 4.
  • ‘no-referrer’ meaning that the Referer header will not be sent.
  • ‘no-referrer-when-downgrade’ meaning that no Referer header will be sent when navigating to an origin without TLS (HTTPS). This is a user agent’s default behavior, if no policy is otherwise specified.
  • ‘origin’ meaning that the referrer will be the origin of the page, that is roughly the scheme, the host and the port.
  • ‘origin-when-cross-origin’ meaning that navigating to other origins will be limited to the scheme, the host and the port, while navigating on the same origin will include the referrer’s path.
  • ‘unsafe-url’ meaning that the referrer will include the origin and the path (but not the fragment, password, or username). This case is unsafe because it can leak origins and paths from TLS-protected resources to insecure origins.
Читайте также:  Java intern all strings

Usage note: This attribute is obsolete in HTML5. Do not use it. To achieve its effect, use the rel attribute with the opposite link types values, e.g. made should be replaced by author . Also this attribute doesn’t mean revision and must not be used with a version number, which is unfortunately the case on numerous sites.

  • any , meaning that the icon can be scaled to any size as it is in a vectorial format, like image/svg+xml .
  • a white-space separated list of sizes, each in the format x or X . Each of these sizes must be contained in the resource.
  • Most icon format are only able to store one single icon; therefore most of the time the sizes contains only one entry. MS’s ICO format does, as well as Apple’s ICNS. ICO being more ubiquitous, you should use it.
  • Apple’s iOS does not support this attribute, hence Apple’s iPhone and iPad use special, non-standard link types values to define icon to be used as Web Clip or start-up placeholder: apple-touch-icon and apple-touch-startup-icon .

target Defines the frame or window name that has the defined linking relationship or that will show the rendering of any linked resource. title The title attribute has special semantics on the element. When used on a it defines a preferred or an alternate stylesheet. Incorrectly using it may cause the stylesheet to be ignored. type This attribute is used to define the type of the content linked to. The value of the attribute should be a MIME type such as text/html, text/css, and so on. The common use of this attribute is to define the type of style sheet linked and the most common current value is text/css, which indicates a Cascading Style Sheet format. It is also used on rel=»preload» link types, to make sure the browser only downloads file types that it supports.

Читайте также:  Javascript наведение на кнопку

Examples

Including a stylesheet

To include a stylesheet in a page, use the following syntax:

Providing alternative stylesheets

The user can choose which style sheet to use by choosing it from the View>Page Style menu. This provides a way for users to see multiple versions of a page.

Stylesheet load events

You can determine when a style sheet has been loaded by watching for a load event to fire on it; similarly, you can detect if an error has occurred while processing a style sheet by watching for an error event:

function sheetLoaded() < // Do something interesting; the sheet has been loaded >function sheetError()

Note: The load event fires once the stylesheet and all of its imported content has been loaded and parsed, and immediately before the styles start being applied to the content.

Preload examples

Notes

  • A tag can occur only in the head element; however, there can be multiple occurrences of .
  • HTML 3.2 defines only the href, rel, rev, and title attributes for the link element.
  • HTML 2 defines the href, methods, rel, rev, title, and urn attributes for the element. The methods and urn attributes were later removed from the specifications.
  • The HTML and XHTML specifications define event handlers for the element, but it is unclear how they would be used.
  • Under XHTML 1.0, empty elements such as require a trailing slash: .

Specifications

Specification Status Comment
Preload Working Draft Defines , and the as attribute.
Subresource Integrity
The definition of » in that specification.
Recommendation Added the integrity attribute.
HTML Living Standard
The definition of » in that specification.
Living Standard No changes from latest snapshot
HTML5
The definition of » in that specification.
Recommendation Added crossorigin and sizes attributes; extended values of media to any media queries; added numerous new values for rel .
HTML 4.01 Specification
The definition of » in that specification.
Recommendation
Resource Hints
The definition of ‘prefetch’ in that specification.
Working Draft Added dns-prefetch , preconnect , prefetch , and prerender .

Browser compatibility

Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) 1.0 (1.0) (Yes) (Yes) (Yes)
Alternative stylesheets ? ? (Yes) 4.0 (2.0) (Yes) ? ?
disabled attribute ? ? (Yes) No support ? No support No support
methods attribute ? ? No support No support 4.0 No support No support
sizes attribute ? ? No support No support bug 441770 No support No support No support
load and error events ? ? ? 9.0 (9.0) ? ? ?
crossorigin attribute ? ? No support 18.0 (18.0) ? ? ?
integrity attribute 45 45.0 No support ? ? ? ?
referrerpolicy attribute 58 58 No support 50.0 (50.0) ? ? ?
prefetch attribute 56 56.0 ? ? ? 43 ?
as attribute (and rel=»preload» ) 50 50 ? 56.0 (56) [2] ? (Yes) ?
[1] WebKit bug 148363 tracks WebKit implementation of Subresource Integrity (which includes the integrity attribute). [2] Firefox supports preloading of the following content ( as values) — script , style , image , video , audio , track , font , and fetch . The list of font types Firefox supports preloading of is defined in the fonts media type list (note font/collection is not supported).

See also

Источник

: The Anchor element

The HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.

Try it

Attributes

This element’s attributes include the global attributes.

Causes the browser to treat the linked URL as a download. Can be used with or without a filename value:

  • Without a value, the browser will suggest a filename/extension, generated from various sources:
    • The Content-Disposition HTTP header
    • The final segment in the URL path
    • The media type (from the Content-Type header, the start of a data: URL, or Blob.type for a blob: URL)
    • download only works for same-origin URLs, or the blob: and data: schemes.
    • How browsers treat downloads varies by browser, user settings, and other factors. The user may be prompted before a download starts, or the file may be saved automatically, or it may open automatically, either in an external application or in the browser itself.
    • If the Content-Disposition header has different information from the download attribute, resulting behavior may differ:
      • If the header specifies a filename , it takes priority over a filename specified in the download attribute.
      • If the header specifies a disposition of inline , Chrome and Firefox prioritize the attribute and treat it as a download. Old Firefox versions (before 82) prioritize the header and will display the content inline.

      The URL that the hyperlink points to. Links are not restricted to HTTP-based URLs — they can use any URL scheme supported by browsers:

      • Sections of a page with document fragments
      • Specific text portions with text fragments
      • Pieces of media files with media fragments
      • Telephone numbers with tel: URLs
      • Email addresses with mailto: URLs
      • While web browsers may not support other URL schemes, websites can with registerProtocolHandler()

      Hints at the human language of the linked URL. No built-in functionality. Allowed values are the same as the global lang attribute.

      A space-separated list of URLs. When the link is followed, the browser will send POST requests with the body PING to the URLs. Typically for tracking.

      How much of the referrer to send when following the link.

      • no-referrer : The Referer header will not be sent.
      • no-referrer-when-downgrade : The Referer header will not be sent to origins without TLS (HTTPS).
      • origin : The sent referrer will be limited to the origin of the referring page: its scheme, host, and port.
      • origin-when-cross-origin : The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.
      • same-origin : A referrer will be sent for same origin, but cross-origin requests will contain no referrer information.
      • strict-origin : Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don’t send it to a less secure destination (HTTPS→HTTP).
      • strict-origin-when-cross-origin (default): Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP).
      • unsafe-url : The referrer will include the origin and the path (but not the fragment, password, or username). This value is unsafe, because it leaks origins and paths from TLS-protected resources to insecure origins.

      The relationship of the linked URL as space-separated link types.

      Where to display the linked URL, as the name for a browsing context (a tab, window, or ). The following keywords have special meanings for where to load the URL:

      • _self : the current browsing context. (Default)
      • _blank : usually a new tab, but users can configure browsers to open a new window instead.
      • _parent : the parent browsing context of the current one. If no parent, behaves as _self .
      • _top : the topmost browsing context (the «highest» context that’s an ancestor of the current one). If no ancestors, behaves as _self .

      Note: Setting target=»_blank» on elements implicitly provides the same rel behavior as setting rel=»noopener» which does not set window.opener .

      Hints at the linked URL’s format with a MIME type. No built-in functionality.

      Deprecated attributes

      Hinted at the character encoding of the linked URL.

      Note: This attribute is deprecated and should not be used by authors. Use the HTTP Content-Type header on the linked URL.

      Used with the shape attribute. A comma-separated list of coordinates.

      Was required to define a possible target location in a page. In HTML 4.01, id and name could both be used on , as long as they had identical values.

      Note: Use the global attribute id instead.

      Specified a reverse link; the opposite of the rel attribute. Deprecated for being very confusing.

      The shape of the hyperlink’s region in an image map.

      Источник

Оцените статью