Creating an Anchor - HTML

Anchor tags have another use; they can be used as a marker in the current document to provide a bookmark that can be directly linked to. For example, a large document might have several sections. You can place links at the top of the document (or in a special navigation frame) to each section, allowing the user to easily access each section.
To create an anchor in a document, you use the anchor tag with the name attribute. For example, the following code creates a chapter anchor at the “Chapter ” heading:

To link to the anchor you use a standard link, but add the anchor name to the end of the URL in the link. To identify the name as an anchor, you separate it from the rest of the URL with a pound sign (#). For example, suppose the Chapter anchor appears in the document book.html.

Note Because the URL in the link tag can contain the server and document names as well as the anchor name, you can link to anchors in the same document or any accessible document. If you are linking to an anchor in the same document, you can use a shortcut form of the URL, using only the pound sign and the anchor name as the URL.

In addition to using the anchor tag for bookmarks, you can link to a block element’s id attribute. For example, if appears inside an <h1> tag, you can set the <h1> tag’s id attribute to Chapter1 and omit the anchor link altogether, as shown in the following code example:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

HTML Topics