Book HomeWeb Design in a NutshellSearch this book

Chapter 11. Creating Links

Contents:

Summary of Tags Related to Linking
Simple Hypertext Links
Linking Within a Document
Affecting the Appearance of Links
Targeting Windows
Imagemaps
Non-Web Links and Protocols
Linking Documents with <link>

The HTML 4.01 specification puts it simply and clearly: "A link is a connection from one web resource to another." This ability to link one document to another is what makes HTML unique among document markup languages and is the key to its widespread popularity.

This chapter focuses on the HTML tags related to linking and building relationships between documents. It includes uses for the anchor tag, linking with imagemaps (both client- and server-side), affecting the appearance of hyperlinks, creating links with non-web protocols, and associating documents with the link tag.

11.1. Summary of Tags Related to Linking

In this section, browser support for each tag is noted to the right of the tag name. Browsers that do not support the tag are grayed out. Tag usage is indicated below the tag name. Start and end tags are required unless otherwise noted. "Deprecated" means that the tag or attribute is currently supported but is due to be phased out of the HTML specification and is discouraged from use (usually in favor of similar style sheet controls). The attributes listed for each tag reflect those in common use. A more thorough listing of attributes for each tag, according to the HTML 4.01 specification, appears in Appendix A, "HTML Elements".

<a>NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<a>...</a>

Defines an anchor within the document. An anchor is used to link to another document or web resource. It can also serve to label a fragment within a document (also called a named anchor), which serves as a destination anchor for linking to a specific point in an HTML document.

Attributes

The attributes labeled "HTML 4.01" are new to the HTML 4.01 specification and are generally supported only by Internet Explorer 5.5 and higher and Netscape 6.

accesskey=character

HTML 4.01. Assigns an access key (shortcut key command) to the link. Access keys are also used for form fields. The value is a single character. Users may access the element by hitting Alt-key (PC) or Ctrl-key (Mac).

charset=charset

HTML 4.01. Specifies the character encoding of the target document. See Chapter 7, "Internationalization" for information on character sets.

coords=x,y coordinates

HTML 4.01. Specifies the x,y coordinates for a clickable area in an imagemap. HTML 4.0 proposes that client-side imagemaps be replaced by an <object> tag containing the image and a set of anchor tags defining the "hot" areas (with shapes and coordinate attributes). This system has not yet been implemented by browsers.

href=url

Specifies the URL of the destination HTML document or web resource (such as an image, audio, PDF, or other media file).

id=text

Gives the link a unique name (similar to the name attribute) so it can be referenced from a link, script, or style sheet. It is more versatile than name, but it is not as universally supported.

hreflang=language code

HTML 4.01. Specifies the base language of the target document. See Chapter 7, "Internationalization" for a list of two-letter language codes.

name=text

Places a fragment identifier within an HTML document. Fragments are discussed further in Section 11.3, "Linking Within a Document" in this chapter.

rel=relationship

Establishes a relationship between the current document and the target document. Common relationships include stylesheet, next, prev, copyright, index, and glossary.

rev=relationship

Specifies the relationship from the target back to the source (the opposite of the rev attribute).

shape=rect|circle|poly|default

HTML 4.01. Defines the shape of a clickable area in an imagemap. This is only used in the <a> tag as part of HTML 4.01's proposal to replace client-side imagemaps with a combination of <object> and <a> tags. This system has not yet been implemented by browsers.

tabindex=number

HTML 4.01. Specifies the position of the current element in the tabbing order for the current document. The value must be between 0 and 32767. It is used for tabbing through the links on a page (or fields in a form).

target=text

Not supported by WebTV or Internet Explorer 2.0 and earlier. Specifies the name of the window or frame in which the target document should be displayed. For more information, see Section 11.5, "Targeting Windows" in this chapter and Section 14.5, "Targeting Frames" in Chapter 14, "Frames".

title=text

Specifies a title for the target document. May be displayed as a "tool tip."

type=MIME type

Specifies the content type (MIME type) of the defined content.

Link Examples

To a local file:

<A HREF="filename.html">...</A>

To an external file:

<A HREF="http://server/path/file.html">...</A>

To a named anchor:

<A HREF="http://server/path/file.html#fragment">...</A>

To a named anchor in the current file:

<A HREF="#fragment">...</A>

To send an email message:

<A HREF="mailto:username@domain">...</A>

To a file on an FTP server:

<A HREF="ftp://server/path/filename">...
</A>
<area>NN 2, 3, 4, 6 MSIE 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<area> (no end tag)

The area tag is used within the <map> tag of a client-side imagemap to define a specific "hot" (clickable) area. Client-side imagemaps are discussed later in this chapter.

Attributes

alt=text

Required. Specifies a short description of the image that is displayed when the image file is not available.

coords=values

Specifies a list of comma-separated pixel coordinates that define a "hot" area of an imagemap. The specific syntax for the coordinates varies by shape (see Section 11.6, "Imagemaps" later in this chapter).

href=url

Specifies the URL of the document or file that is accessed by clicking on the defined area.

nohref

Defines a "mouse-sensitive" area in an imagemap for which there is no action when the user clicks in the area.

shape=rect|circle|poly|default

Defines the shape of the clickable area.

<base>NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<base> (no end tag)

Specifies the base pathname for all relative URLs in the document. Place this element within the <head> of the document.

Attributes

href=url

Required. Specifies the URL to be used.

target=name

Defines the default target window for all links in the document. Often used to target frames. (This attribute is not supported in MSIE 2.0.)

<link>NN 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<link> (no end tag)

Defines a relationship between the current document and another document. This tag goes within the <head> portion of the document. It is often used to refer to an external style sheet.

Attributes

href=url

Identifies the target document.

media=screen|tty|tv|projection|handheld|print|braille|aural|all

Identifies the target medium for the linked document so an alternate style sheet can be accessed. The media attribute is explained in more detail in Chapter 5, "Printing from the Web".

rel=relation

Describes the relationship from the current source document to the target. Common relationship types include stylesheet, next, prev, copyright, index, and glossary.

rev=relation

Specifies the relationship of the target document back to the source (the opposite of the rel attribute).

title=text

Provides a title for the target document.

type=resource

Shows the type of an outside link. The value text/css indicates that the linked document is an external cascading style sheet.

<map>NN 2, 3, 4, 6 MSIE 2, 3, 4, 5, 5.5, 6 HTML 4.01 WebTV Opera5

<map>...</map>

Encloses client-side imagemap specifications. Client-side imagemaps are discussed later in this chapter.

Attributes

name=text

Gives the imagemap a name that is then referenced within the <img> tag. This attribute is required.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.