Creating a Hyperlink or Anchor (<a>)

The <a> element creates a hyperlink (use the href attribute) or anchor (use the id or the deprecated name attribute for browsers that need to use name, such as Netscape). This element is supported in XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, and XHTML 1.1. Here are this element's attributes:

AttributeDescription
accesskeyAssigns a keyboard access key to the hyperlink. (XHTML 1.0 Strict, XHTML 1.0 Transitional.)
charsetIndicates the character encoding of the hyperlink's target. Set this to an RFC (Request for Comments) 2045 language character set string. The default value is ISO-8859-1.
classGives the style class of the element.
coordsSets the coordinate values (in pixels) appropriate to the corresponding shape attribute to define a region of an image for image maps.
dirSets the direction of text that doesn't have an inherent direction in which you should read it, called directionally neutral text. You can set this attribute to ltr, for left-to-right text, or rtl, for right-to-left text.
hrefHolds the target URI of the hyperlink. You must assign a value to either this attribute or the id attribute.
hreflangGives the base language of the target indicated in the href attribute. Set this to RFC 1766 values.
idUse the ID to refer to the element; set this attribute to a unique identifier.
langSpecifies the base language used in the element. Applies only when the document is interpreted as HTML.
nameIs available in the three XHTML 1.0 DTDs, but is deprecated and not available in the XHTML 1.1 DTD (use id instead). Gives the anchor a name, which may be used as the target of a hyperlink. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset.)
relSpecifies the relationship described by the hyperlink.
revIs the same as the rel attribute, but the syntax works in the reverse direction. For example, a link from A to B with rel="X" signifies the same relationship as a link from B to A with rev="X".
shapeSpecifies the type of region for mapping in an <area> element. Used with the coords attribute. Possible values are rect (the default), circ, circle, POLY, and polygon.
styleIs an inline style indicating how to render the element.
tabindexSpecifies the tab sequence of hyperlinks in the page for keyboard navigation. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset.)
targetIndicates the named frame that serves as the target of the hyperlink. (XHTML 1.0 Transitional, XHTML 1.0 Frameset.)
titleContains the title of the element (which might be displayed in ToolTips).
typeSpecifies the Multipurpose Internet Mail Extensions (MIME) type of the target given in the href attribute.
xml:langSpecifies the base language for the element when the document is interpreted as an XML document.

This element supports these XHTML events: onclick, ondblclick, onfocus, onblur, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, and onkeyup.

The <a> element is a big part of what makes the Web work. You use this element to create hyperlinks and anchors (an anchor can serve as the target of a hyperlink). In this element, you must set either the href attribute to set the target URI of a hyperlink, or the id attribute to create an anchor. Here's an example using href, specifying the W3C site as the target of a hyperlink:

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>
            Using the &lt;a&gt; Element
        </title>
    </head>

    <body>

       <center>

           <h1>
            Using the &lt;a&gt; Element
           </h1>

           Want to learn more about XHTML? Go to:
           <a href="http://w3c.org">W3C</a>
       </center>

    </body>
</html>

You can see the results of this XHTML in Figure 17.2; as is standard in HTML browsers, the hyperlink appears as underlined text (largely because the browser thinks that this is standard HTML). You can also use graphical hyperlinks if you enclose an <img> element in the <a> element.

Figure 17.2. Displaying a hyperlink.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.45.212