HTML <link> tag
The <link> tag links external style sheets.
The external style sheets helps to style the HTML document.
You must place this tag inside the <head> section of the HTML document. The <link> tag can appear any number of times.
Syntax:
<link rel=”stylesheet” href=”testfile.css”>
Example
<head> <title>Page Title</title> <link rel="stylesheet" href="testfile.css"> </head>
CSS Default Value
display: none;
Difference between HTML4.01, XHTML and HTML5
HTML4 | XHTML | HTML5 |
---|---|---|
Does not have an End tag | Must use End tag as <link .... />. | HTML5 does not support all the attributes of HTML4.01. A new size attribute is also added. |
Attributes used with <link> tag
Attribute | Description |
---|---|
crossorigin | This attribute controls the cross-origin requests on the <link> element. It can either take a value of use-credentials or anonymous. |
href | Sets the URL/Location of the target document which is linked from the current document. |
hreflang | This attribute defines the language of the text of the target document which is linked from the current document. It uses a language_code for this purpose. Examples are - hrefland="en", hrefland="fr" etc. This is a 2 digit language code. |
media | Uses a media query to display the media device where the target link document will be displayed. |
sizes | To control the size of the target icon. Most of the browsers does not support this attribute. |
type | To define the type of media for the target linked document using a media_tpe. |
media | It specifies that for what purpose of linked document is optimized. This attribute also accepts several values. It describes the purpose of target URL. It can accept values as - |
charset | To define the character encoding of the target document which is linked from the current document. It uses a character_encoding for this purpose. (HTML5 does not support this attribute when it is used with the <link> tag). |
rev | To define a reverse relationship between the target document to the current document. (HTML5 does not support this attribute when it is used with the <link> tag). |
target | To define where the target document(linked document) will open. It will take values as - (HTML5 does not support this attribute when it is used with the <link> tag). |
Global Attributes
The <link> tag supports Global attributes.
Event Attributes
The <link> tag supports Event attributes.
Supporting Browsers
Related Tags
<head> and <style> tags.