<link>

Draft

Definition

The <link> HTML element is used to establish a link between an HTML document and an external resource. It is commonly used to link stylesheets, icon files, or other external resources to the HTML document.

Here’s an example of how to use the <link> element to link a CSS stylesheet:

<head>
  <link rel="stylesheet" href="styles.css" />
</head>

In this example, the <link> element is placed within the <head> section of the HTML document. The rel attribute specifies the relationship between the current document and the linked resource, in this case, “stylesheet”. The href attribute specifies the URL or file path of the external CSS file to be linked.

The <link> element can also be used to link other types of resources, such as icon files or alternate versions of the document. For example:

<head>
  <link rel="icon" href="favicon.ico" type="image/x-icon" />
  <link
    rel="alternate"
    href="alternate.html"
    type="text/html"
    title="Alternate Version"
  />
</head>

In this example, the first <link> element is used to link a favicon, which is the small icon displayed in the browser’s tab or bookmark. The type attribute specifies the MIME type of the linked resource. The second <link> element is used to link an alternate version of the document, with the type attribute indicating the media type and the title attribute providing a descriptive title.

The <link> element is an empty element and does not require a closing tag. It is commonly placed within the <head> section of an HTML document.