link (HTML element)
| Depr. | Empty | Version |
|---|---|---|
| No | Yes | HTML 2 |
| IE5.5+ | FF1+ | SA1.3+ | OP9.2+ | CH2+ |
|---|---|---|---|---|
| Partial | Partial | Partial | Partial | Partial |
Syntax
Description
The
link element is used to create links between the
referencing document and an external resource; we define the type of this
relationship with the use of the rel and rev attributes. The
link element is most commonly used for the purpose of
linking to one or more style sheets for the document, but may also be used
to identify relationships between web pages—for example, which page is the
logical next or previous page in a sequence, which page is the contents
page for the current page, and so on. Although this use of the
link element is well intended, it has few practical
uses for the person browsing your site, as the navigation-type link
relationships don’t provide any clear method of navigating—the user still
needs to use whatever controls are visible on the page.
Arguably, it may be better to avoid using the
link element for anything other than linking
to a style sheet if you’re hand-coding your web site. If your web site’s
content is dynamically generated, it may not be difficult to automatically
identify the necessary relationships in the link
element. On the other hand, if the web site is a roll-your-own affair, it
may constitute an unnecessary overhead, and one that’s soon
neglected.
The link may only appear
in the head, but there’s no limit to
the number of individual link elements that you can
include (a quick look at the source code of any blog powered by WordPress
reveals a whole raft of auto-generated link elements
relating to archives).
Example
In this example, a
link element references a style sheet for the current
document:
<link rel="stylesheet" href="basic.css"/>
Use This For …
This element’s used to link to style sheets, and to define relationships between pages—particularly in CMS-generated sites that can automate this process.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
| Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial | Partial |
Excellent browser support is provided for referencing external style sheets, but there’s no real support for anything else.
In this Section
- charset
identifies the character set used in the referenced (or linked) document - href
specifies the location of the document or resource reference in the link element - media
defines the types of media that the referenced resource (such as a style sheet) should apply to - rel
defines the relationship of the resource that’s being linked to - rev
defines the relationship the referenced resource classifies itself as having with the referencing document - target
defines the window or frame in which the referenced document resides - type
defines the MIME type of the referenced resource, commonly a style sheet