English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Encyclopedia

HTML: <link> tag

The HTML <link> tag links external resources (such as CSS files) to the HTML document. This tag is also commonly referred to as the <link> element.

Online Example

Link to external style file:

!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>Basic Tutorial Website(oldtoolbag.com)</title> 
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
</body>
</html>
Test and see ‹/›

HTML <link> tag syntax-Linking Style Sheets

The syntax for linking style sheets using HTML <link> tag is:

<head>
<link rel="stylesheet" href="/css/main.css" type="text/css">
</head>

Or in XHTML, the syntax of the <link> tag is:

<head>
<link rel="stylesheet" href="/css/main.css" type="text/css" />
</head>

Browser Compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the <link> tag.

Definition and Usage Description

The <link> tag is most commonly used to link style sheets or CSS files to HTML documents.

The <link> tag defines the relationship between the document and external resources.

The most common use of the <link> tag is to link style sheets.

Note: The <link> element is an empty element, it only contains attributes.

Note: This element can only exist in the head section, but it can appear any number of times.

HTML 4.01 and HTML5Differences between

Some HTML 4.01 Attribute in HTML5 Not supported in Chinese.

HTML5 The "sizes" attribute has been added.

Differences between HTML and XHTML

In HTML, the <link> tag does not have a closing tag.

In XHTML, the <link> tag must be closed correctly.

Attribute

AttributeValueDescription
charsetchar_encodingHTML5 This attribute is not supported. Define the character encoding method of the linked document.
hrefURLDefine the location of the linked document.
hreflanglanguage_codeDefine the language of the text in the linked document.
mediamedia_queryThe linked document will be displayed on what device.
relalternate
archives
author
bookmark
external
first
help
icon
last
license
next
nofollow
noreferrer
pingback
prefetch
prev
search
sidebar
stylesheet
tag
up
Required. Defines the relationship between the current document and the linked document.
revreversed relationshipHTML5 This attribute is not supported. Defines the relationship between the linked document and the current document.
sizesHTML5HeightxWidth
any
Defined the size of the link attribute, only effective for the attribute rel="icon".
target_blank
_self
_top
_parent
frame_name
HTML5 This attribute is not supported. Defines where to load the linked document.
typeMIME_typeSpecifies the MIME type of the linked document.

Global Attributes

<link> tag supports global attributes, see the complete attribute table HTML Global Attributes.

event attributes

<link> tag supports all HTML Event Attributes.

Related Articles

HTML Tutorial:HTML Styles

HTML DOM Reference Manual:Link Object