The <link>
tag in HTML is used to link external resources, such as stylesheets or icons, to an HTML document. Here are the commonly used properties:
rel
Attribute:
- Defines the relationship between the current document and the linked resource. Common values include:
stylesheet
: Links to an external stylesheet.icon
: Specifies a favicon or app icon.
href
Attribute:
- Specifies the URL of the linked resource.
media
Attribute:
- Specifies the media type for which the linked stylesheet is intended. Example:
media="screen"
.
type
Attribute:
- Defines the type of the linked resource. For stylesheets, it is typically
text/css
.
sizes
Attribute:
- Specifies the sizes of the linked icon for different display densities. Example:
sizes="16x16 32x32"
.
crossorigin
Attribute:
- Controls how the browser handles cross-origin requests. Common values include:
anonymous
: No credentials are sent.use-credentials
: Credentials are sent if the requesting origin is a same-origin.
integrity
Attribute:
- Provides a subresource integrity (SRI) value, ensuring the resource hasn't been tampered with.
as
Attribute:
- Specifies the type of the resource. For example,
as="font"
oras="image"
.
charset
Attribute:
- Specifies the character encoding for the linked resource.
title
Attribute:
- Describes the linked resource. Useful for accessibility.
disabled
Attribute:
- Disables the link, preventing the linked resource from being applied.
<!-- Linking an external stylesheet -->
<link rel="stylesheet" type="text/css" href="styles.css">
<!-- Linking a favicon -->
<link rel="icon" type="image/png" href="favicon.png">