Description
The HTML element <link>
is used to define a link between the current document and an external resource.
It is defined inside the <head>
element and can appear any number of times.
The below table summarizes its usage.
Usage Details | |
Parent Elements | <head> |
Placement | It must be defined within the <head> element. |
Contents | No, It is an empty element. |
Tags | Only an opening tag is required. |
Versions | HTML 2, 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <link>
element.
<link href="">
Examples
The element <link>
is used to link an external CSS style sheet.
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Element - link</title>
<link rel="stylesheet" href="/assets/css/default.css">
</head>
<body>
<h1>Heading</h1>
<p>Paragraph content goes here.</p>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <link>
element.
Attribute Type | Details |
Element-Specific Attributes | The tags <link> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <link> supports the HTML Global Attributes. |
Event Attributes | The tags <link> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <link>
element.
Attribute | Value | Description |
charset |
charset | Obsolete Specifies the character encoding of the linked resource. |
crossorigin |
anonymous |
Specifies how the element handles cross-origin requests. |
href |
URL | Specifies the location of a linked document. |
hreflang |
language-code | Specifies the language of the linked document when the attribute href is specified. |
media |
media-types | Specifies the media to which the linked resource applies. The default value is screen . |
rel |
alternate |
Specifies the relationship of the linked resource to the current document. This attribute should be used only if the href attribute is present. |
rev |
link-type | Obsolete Describes the relationship of the linked document back to the source document (the opposite of the rel attribute). |
sizes |
HeightxWidthany |
Specifies the size of the icons (for rel="icon" ). |
target |
_blank framename |
Obsolete Defines where to open the linked document specified in the href attribute. |
type |
content-type | Specifies the content type of the linked document. The most common value is text/css , which indicates a Cascading Style Sheet format. |
Browser Compatibility
The tags <link>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 3+
- Firefox 1+
- Apple Safari 1+
- Opera 4+