<link>

The HTML <link> element defines the connection between the current document and external resources, often used to link stylesheets, icons, and other files within the <head> section.

The <link> HTML element specifies the relationship between the current document and an external resource. It is primarily used to link stylesheets but also serves other purposes, such as defining site icons like favicons and mobile app icons.

index.html
<head>
  <link rel="stylesheet" href="styles.css" type="text/css">
</head>

Attributes

AttributeValueDescription
crossoriginanonymous, use-credentialsDetermines how cross-origin requests are handled
hrefURLSpecifies the location of the linked document
hreflanglanguage_codeDefines the language of the linked document
mediamedia_querySpecifies the media type for the linked document
referrerpolicyno-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, unsafe-urlControls the referrer information sent with requests
relalternate, author, dns-prefetch, help, icon, license, next, pingback, preconnect, prefetch, preload, prerender, prev, search, stylesheetRequired. Defines the relationship between the current document and the linked document
sizesHeightxWidth, anySpecifies the size of the linked resource (only applicable for rel="icon")
title-Defines a preferred or alternate stylesheet
typemedia_typeSpecifies the media type of the linked document

Definition and Usage

  • The <link> tag establishes a connection between the current document and an external resource.
  • It is commonly used to link external stylesheets or set a favicon for the website.
  • The <link> element is self-closing and only includes attributes.

Key Points

  • Placement: Inside the <head> element.
The <link> element should be placed within the <head> section and can be used multiple times to link various resources.

Default CSS Settings

In most web browsers, the <link> element is typically rendered using these default settings:

style.css
link {
  display: none;
}

Conclusion

The <link> tag is used to link external resources, such as stylesheets and favicons, to a webpage. Placed within the <head> section, it helps define the relationship between the current document and the linked resource using attributes like href, rel, and type. This tag is essential for improving web page styling, design, and overall functionality.