asp.net.ph

Skip Navigation LinksHome > Abakada: Back to Basics > Authoring Your Web Pages > Anchors and Links

Anchors and Links

Previous: HTML Elements   Next: Using Tables


Linking to a location within a document

The target of a link may be set to an element within the same or another HTML document.

To specify an element as a destination, the element must be given an anchor name, either by the A element’s name attribute, or by the element’s id attribute.

To create a destination anchor using the A element’s name attribute, we would write:

<H2><a name="section1">Introduction</a></H2>
... contents of section 1 here below ...

which specifies a heading element that can be the target of any other link, such as an entry in a file’s table of contents, or for cross-reference purposes.

To create a destination anchor using the id attribute, we would write:

<H2 id="section2">How Links Work</H2>
... contents of section 2 here below ...

We can use the id attribute to create a destination anchor in any element, such as a paragraph:

<P id="howto">... contents of paragraph ...</p>

NOTE: Using IDs as target anchors is supported only in later versions of the available browsers.

The following example shows how links may be used to access named sections within the same page:

<ul>
   <li><a href="#how">How HyperText Links Work</a>
   <li><a href="#specify">Specifying Anchors and Links</a>
   <li><a href="#elem_a">The A Element</a>
   <ul>
      <li><a href="#getfile">Linking to a document</a>
      <li><a href="#open">Specifying how to open a linked resource</a>
      <li><a href="#getloc">Linking to a location within a document</a>
   </ul>
   <li><a href="#elem_link">The LINK Element</a>
</ul>

Any link targeting a destination anchor that is on a different document must include the relative URI with the name or id of the anchor as its fragment identifier, as in:

<a href="../authoring.html#uri">Introduction to URIs</a>

Web Authoring Basics has more information on fragment identifiers and relative URIs.

Authors may set the name and href attributes simultaneously in the same A declaration, thereby specifying hypertext that can both be a source and a destination of a link at the same time.


More ...
Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note