Using the tag and the name attribute to implement page navigation#
In HTML, the name attribute of the tag is usually used to define named anchors, rather than for link navigation. To implement link navigation, the href attribute of the tag is typically used.
When creating named anchors, you can use the tag and the name attribute anywhere in the document to create an anchor. Then, you can use a link with the # symbol in other parts of the document to reference this anchor and navigate to the location of the anchor.
For example, we can create an anchor named section1 in HTML as shown below:
<a name="section1"></a>
In other parts of the same document, we can use the following link to navigate to this anchor:
<a href="#section1">Jump to Section 1</a>
When clicking on this link, the browser will navigate to the location of the anchor named section1 defined in the document. Please note that the href attribute value starts with the # symbol because we are navigating to a named anchor.
There is another way to navigate to named anchors, which is to use a non-empty id attribute instead of the name attribute. This is because in HTML5, using the name attribute to create named anchors has been deprecated. Using the id attribute to create named anchors is a more modern and compliant approach.