Cover Image for HTML link Tag
73 views

HTML link Tag

The <link> tag is an HTML element used to link external resources to an HTML document. It is commonly used to link stylesheets, define the document’s relationship with external files, and specify alternate versions of the document.

The <link> tag is a self-closing tag and does not require a closing tag. Here are some common use cases of the <link> tag:

1. Linking Stylesheets:

HTML<span role="button" tabindex="0" data-code="
<link rel="stylesheet" href="styles.css">

In this example, the <link> tag is used to link an external CSS stylesheet file called “styles.css” to the HTML document. This allows the styles defined in the stylesheet to be applied to the HTML elements.

2. Specifying Document Relationships:

HTML<span role="button" tabindex="0" data-code="
<link rel="icon" href="favicon.ico" type="image/x-icon">

This <link> tag specifies the relationship between the HTML document and a favicon (website icon). The rel attribute with a value of “icon” indicates that the linked file is an icon for the document, and the href attribute provides the path to the icon file.

3. Linking Alternate Versions:

HTML<span role="button" tabindex="0" data-code="
<link rel="alternate" href="feed.xml" type="application/rss+xml" title="RSS Feed">

Here, the <link> tag is used to specify an alternate version of the document in the form of an RSS feed. The rel attribute with a value of “alternate” indicates that the linked document is an alternate version, the href attribute specifies the path to the RSS feed file, and the type attribute defines the MIME type of the linked file.

The <link> tag supports various attributes, including:

  • rel: Specifies the relationship between the HTML document and the linked resource.
  • href: Specifies the URL or path to the linked resource.
  • type: Specifies the MIME type of the linked resource.
  • media: Specifies the media type or media query for which the linked resource is intended.
  • sizes: Specifies the sizes of the linked resource for responsive designs.
  • integrity: Specifies a cryptographic hash value used for Subresource Integrity (SRI) checking.

The <link> tag is primarily used in the <head> section of an HTML document to define external resources and their relationships. It helps separate the structure and content of the document from its presentation and functionality.

Make sure to provide accurate and valid attributes when using the <link> tag to ensure proper linking and functionality of external resources in your HTML document.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS