Demonstrating Anchors

Up until now, the links you have created have been from one point in a page to another page. In XHTML, you can use anchors to create special elements that link from one part of the page to another.

Section 1

You create an anchor in almost the same way you create a hyperlink. Instead of using "href" to specify a filename and location, you use "id" to identify a section.

back to top

Section 2

Anchors require some amount of text (or a graphic) between the opening and closing tags, although they can point to just a single character. Unlike links, anchors do not show up on the web page.

To point to an anchor on the page, you use the same "href" attribute as you would normally use in a hyperlink, substituting the filename for the anchorname preceeded by the pound (#) sign.

back to top

Section 3

You can also use point to places on a different web page instead of the same one. Amending "href" to read "filename.html#part4" would send the user to "part 4" on the new page.

This link sends you to the specifications for the second edition of XHTML 1.0 on the World Wide Web Consortium's website.

back to top