Link Tag in HTML
<link> tag is an HTML element used to link external resources, such as stylesheets, to an HTML document. The
<link> tag should be placed in the
<head> section of an HTML document.
Here is a basic example of the
<head> <link rel="stylesheet" type="text/css" href="style.css"> </head>
rel attribute specifies the relationship between the linked resource and the HTML document. For a stylesheet, the value should be set to "stylesheet".
type attribute specifies the type of the linked resource. For a stylesheet, the value should be set to "text/css".
href attribute specifies the URL of the linked resource.
<link> tag can also be used to link to other resources, such as favicons, using the appropriate
rel value. For example, the following
<link> tag links to a favicon:
<link rel="icon" type="image/x-icon" href="favicon.ico">
It's worth noting that the
<link> tag does not have a closing tag, and the
</link> tag should not be used.
<link> tag also supports several other attributes that can be used to provide additional information about the linked resource:
media: Specifies the media types for which the linked resource is intended. This attribute can be used to specify stylesheets that are intended for specific devices, such as printers or screens.
sizes: Specifies the size of icons for visual media. This attribute is used in conjunction with the
relattribute to specify the size of a favicon.
hreflang: Specifies the language of the linked resource. This attribute is useful for linking to resources in different languages.
crossorigin: Specifies whether to allow CORS (Cross-Origin Resource Sharing).
title: Provides a title for the linked resource. This attribute is used primarily for stylesheets and is displayed in some browsers' user interfaces.
It is important to use the
<link> tag correctly in order to ensure that your HTML documents are properly linked to their associated resources and display as intended.
In summary, the
<link> tag is an essential part of HTML, used to link external resources, such as stylesheets, to an HTML document. By using the
href attributes, along with other optional attributes, you can provide additional information about the linked resource, enabling you to create well-structured and well-designed HTML documents.