HTML <link> Tag
To link an external source to the current document, the HTML <link> tag is used. It can also be used with link site icons. It is placed within the <head> tag of the HTML document.
Syntax:
<link rel="stylesheet" type="text/css" href="">
Example:
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <h1>HELLO WORLD!!</h1> <p>Today is a Great Day..</p> </body> </html>
Explanation:
In the above example, we are using the HTML <link> tag to link an external CSS file to an HTML document.
Tag Specific Attributes:
Attribute | Value | Uses | |
charset | char_encoding | Used to specify the character encoding of the linked source. | Not supported in HTML5. |
href | URL | Used to determine the location of the linked document. | |
hreflang | language_code | Used to determine the text language of the linked source. | |
media | media_query | Used to define the media, for which linked source is applied. | |
rel | alternate
author dns-prefetch help icon license next pingback preconnect prefetch preload prerender prev search stylesheet |
Used to specify the relationship between the current and the linked document. It is a required attribute of the HTML <link> tag. | |
rev | reversed
relationship |
Used to specify the relationship between the link and the current document. | Not supported in HTML5. |
sizes | Height* weight | Used to determine the size of the linked source, and is used with rel=”icon.” | |
target | _blank
_self _top _parent frame_name |
Used to specify where to load the linked document. | |
type | media_type | Used to determine the media type of document. |
Global Attributes:
The HTML Global attributes are supported by the HTML <link> tag.
Event Attributes:
The HTML Event attributes are supported by the HTML <link> tag.
Supporting Browsers:
Chrome, IE, Firefox, Opera, and Safari.