English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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 ‹/›
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>
IEFirefoxOperaChromeSafari
All mainstream browsers support the <link> tag.
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.
Some HTML 4.01 Attribute in HTML5 Not supported in Chinese.
HTML5 The "sizes" attribute has been added.
In HTML, the <link> tag does not have a closing tag.
In XHTML, the <link> tag must be closed correctly.
Attribute | Value | Description |
---|---|---|
charset | char_encoding | HTML5 This attribute is not supported. Define the character encoding method of the linked document. |
href | URL | Define the location of the linked document. |
hreflang | language_code | Define the language of the text in the linked document. |
media | media_query | The linked document will be displayed on what device. |
rel | alternate 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. |
rev | reversed relationship | HTML5 This attribute is not supported. Defines the relationship between the linked document and the current document. |
sizesHTML5 | HeightxWidth 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. |
type | MIME_type | Specifies the MIME type of the linked document. |
<link> tag supports global attributes, see the complete attribute table HTML Global Attributes.
<link> tag supports all HTML Event Attributes.
HTML Tutorial:HTML Styles
HTML DOM Reference Manual:Link Object