O'Reilly logo

HTML & XHTML: The Definitive Guide, 5th Edition by Chuck Musciano, Bill Kennedy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Hyperlinks

Use the HTML/XHTML <a> tag to create links to other documents and to name anchors for fragment indentifiers within documents.

The <a> Tag

You will use the <a> tag most commonly with its href attribute to create a hypertext link, or hyperlink, to another place in the same document or to another document. In these cases, the current document is the source of the link; the value of the href attribute, a URL, is the target.[42]

The other way you can use the <a> tag is with the name attribute, to mark a hyperlink target, or fragment identifier, in a document. This method, although part of the HTML 4 and XHTML standards, is slowly succumbing to the id attribute, which lets you mark nearly any element, including paragraphs, divisions, forms, and so on, as a hyperlink target.

The standards let you use both the name and href attributes within a single <a> tag, defining a link to another document and a fragment identifier within the current document. We recommend against this, since it overloads a single tag with multiple functions and some browsers may not be able to handle it. Instead, use two <a> tags ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required