
- HTML - Home
- HTML - Roadmap
- HTML - Introduction
- HTML - History & Evolution
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <link> Tag
Introduction to <link> Tag
The HTML <link> tag is a self closing tag that is used to define the relationship between the current document and external resources, such as style-sheet, icons and other linked documents.
It is commonly used within the <head> section of an HTML document to link the external resources that improves the functionality or appearance of the page. It also uses the attributes like rel, href and type to specify the relationship.
Syntax
Following is the syntax of HTML <link> tag −
<link href="..." rel=".."/>
Attributes
HTML link tag supports Global and Event attributes of HTML. Accept some specific attributes as well which are listed below.
Attribute | Value | Description |
---|---|---|
crossorigin | anonymous use-credentials |
Specifies how the element handles cross-origin requests. |
href | URL | Specify the link page which we wants to link. |
hreflang | language_code | Spefeicy the language of the attached link. |
media | media_query | Specifies what media/device the linked document is optimized for. |
referrerpolicy | no-referrer no-referrer-when-downgrade origin origin-when-cross-origin unsafe-url |
Specifies which referrer information to send with the link. |
rel | alternate author dns-prefetch help icon license next pingback preconnect prefetch preload prerender prev search stylesheet |
Define the relation between the current and linked url document. |
sizes | HeightxWidth any |
Specifies the size of the linked resource. Only for rel="icon". |
title | Specifies a preferred or an alternate stylesheet. | |
type | media_type | Specify the media type of the inked url document. |
Example : Linking External CSS
Let's look at the following example, where we are going to link the external CSS file style.css to the HTML document.
index.html
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Anchor Tag</title> <!--create a link tag--> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Hello World!</h1> </body> </html>
style.css
body{ background-color: green; } h1{ color: white; font-size: 40px; }
Example : Using Attributes
Consider the following example, where we are going to use the rel, href and size attributes along with the <link> tag.
<!DOCTYPE html> <html lang="en"> <head> <title>Link Tag</title> <!--create a link tag--> <link rel="icon" type="image/x-icon" href="simply-easy-learning.png" sizes="500x500"> <style> body { background-color: rgb(14, 116, 211); font-family: initial; font-size: 16px; color: white; } </style> </head> <body> <h1>favicon with <pre> <link> </pre> tag </h1> </body> </html>
Example : Favicon for Website
In the following example, we are going to create the favicon on the browser using the <link> tag.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Anchor Tag</title> <!--create a link tag--> <link rel="icon" type="image/x-icon" href="download.png"> <style> body { background-color: aquamarine; font-family: initial; font-size: 20px; } </style> </head> <body> <h1> The <pre> <link> </pre> tag with the favicon icon...... </h1> </body> </html>
Example : Providing Print Media
Following is the example, where are going to provide the media type or query inside the media attribute.
index.html
<!DOCTYPE html> <html lang="en"> <head> <title>Link Tag</title> <!--create a link tag--> <link href="print.css" rel="stylesheet" media="print" /> <link href="style.css" rel="stylesheet" media="screen and (max-width: 680px)" /> </head> <body> <h1>The <pre> <link> </pre> tag with media attribute </h1> </body> </html>
print.css
body{ background-color: aquamarine; color: white; }
style.css
body{ background-color: green; } h1{ color: white; font-size: 40px; }
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
link | Yes | Yes | Yes | Yes | Yes |