Linking Within a Document
By default, when you link to a page, the browser displays the top of that page. To aid in navigation, you can use the anchor tag to link to a specific point or section within a document. This navigation technique is only effective on long documents. Linking to specific destinations in a document is a two-step process in which you place a marker in the document and give it a name, and then you make a link to that marker.
Naming a fragment
First,
identify and name the portion of the document (called a fragment)
that you want to link to. The fragment is marked using the anchor
(<a>) tag with its name
attribute, giving the document fragment a name that can be referenced
from a link. Named anchors receive no special style treatment by
default (as <a
href>
links do).
To illustrate, let’s set up a named fragment within a sample
document called dailynews.html so users can link
directly to the Stock Quotes section of the page. The following
anchor tag marks the Stock Quotes title as a fragment named
“stocks”.
<H1><A NAME="stocks">Daily Stock Quotes</A></H1>
Fragments can also be named using the id
attribute in any element tag. Keep in
mind that the id attribute is a newer addition to
the HTML specification, so it is not supported in older browsers. In
this example, the heading itself serves as a marker:
<H1 ID="stocks">Daily Stock Quotes<H1>
The value of the name and id attributes must be unique within the document (in other words, two elements can’t be given the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access