Writing HTML | About | FAQ | Tags | back | next |

13. Links to Sections of a Page
You have seen how to link to other web pages, whether they are ones you created or have found elsewhere on the Internet. What if you wanted to connect to a specific section within a document? YOU CAN!
Objectives
After this lesson you will be able to:
Lesson
The Named Anchor
A named anchor is a hidden reference marker for a particular section of your HTML file. This might be used to link to a different section of the same page (like quickly scrolling) or to a marked section of another page. For example, on this page you are viewing, I could create a hidden marker called "check" that marked the heading below "Check Your Work". Then, I write an anchor link that connects to this section of this document. Once you click on a link to this named anchor, your web browser will jump so this line is at the top of the screen.
Here is an example you can try right now. Go to Check Your Work and when you get there look for a link that will return you to this section.
The HTML format for creating the named anchor is:
<a name="NAME">Text to Link To</a>
or for the link you just tried above:
<a name="check">Check Your Work</a>
Notice how this subtly differs from the anchor link <a href=... that we learned about in lesson 8a.
Writing a Link to a Named Anchor
When you want to create an hypertext link (or an "anchor link", see lesson 8a) to a named anchor, use the following HTML:
<a href="#xxxxx">Text to act as hypertext</a>
or for the link you just tried that sent you to the section below:
Go to <a href="#check">Check Your Work</a>
The "#" symbol instructs your web browser to look through the HTML document for a named anchor called "xxxxxx" or in our example "check". When you select or click on the hypertext, it brings the part of the document that contains the named anchor to the top of the screen.
Adding Named Anchors to the Volcano Web Lesson
Now, we will build a table of contents for our lesson that will appear at the top of our Volcano Web page. The entries for this will be the headings we have already created. Each will act as a hypertext link to a particular section of our lesson.
The first step is to create a named anchor for each of the heading sections in your Volcano Web lesson:
<h2>Introduction</h2>
so that it looks like:
<h2><a name="intro">Introduction</a></h2>
NOTE: You have just marked the line that contains the header "Introduction" with a hidden reference marker, the named anchor "intro"
<h2><A NAME="term">Volcano Terminology</A></h2> <h2><A NAME="usa">Volcanic Places in the USA</A></h2> <h2><A NAME="mars">Volcanic Places on Mars</A></h2> <h2><A NAME="project">Research Project</A></h2>
Adding Links to a Named Anchor in the Same Document
Now we will set up a table of contents that will appear at the top of the screen. We will use an unordered list (see lesson 6 for more on lists) to create this list:
<hr> <B>In this Lesson...</B> <ul><i> <li>Introduction <li>Volcano Terminology <li>Volcanic Places in the USA <li>Volcanic Places on Mars <li>Research Project</i> </ul>
NOTE: This index is marked off above and below by a solid line using the <hr> tag. The Italic style is used on the entries for the text. At this point we have only entered the text of the index entries. Below we will add the HTML to make the links active.
Finally, we want to make each item of the list act as a hypertext link to another section of the document. To do this, we will use a variation of the basic anchor link lessons 10. Rather then linking to another file, we link to one of the named anchors within the file. We indicate a named anchor by preceding the reference marker name with a "#" symbol:
<li>Introduction
to look like:
<li><A HREF="#intro">Introduction</A>
<hr> <B>In this Lesson...</B> <ul><i> <li><A HREF="#intro">Introduction</A> <li><A HREF="#term">Volcano Terminology</A> <li><A HREF="#usa">Volcanic Places in the USA</A> <li><A HREF="#mars">Volcanic Places on Mars</A> <li><A HREF="#project">Research Project</A></i> </ul>
Adding Links to a Named Anchor in Another Document
You can create a link that jumps to a section of another HTML document that is marked by a named anchor. The HTML for building a link to a named anchor in another HTML document is:
<a href=file.htm#NAME>Text to activate link</a>
In lesson 10 we created an hypertext link that jumped from the section of our lesson on Mount St. Helens to msh.html, a separate HTML file. Now we will add a link in that second document that will return to the original section of the main Volcano page.
<hr> <a href="index.htm#usa">Return to <i>Volcano Web</i></a>
NOTE: We have included the Italic Style tag <i>...</i> within the text marked by the named anchor "usa".
In this case the link is just the name of another HTML file, msh.html, in the same directory as the index.html file. However, you can use a full URL (see lesson 7) to link to a named anchor in an HTML file on a remote computer. For example, to create a link to the "Introduction" section of an HTML file stored on the MCLI WWW server, the syntax would be:
<a href=http://michel.simplenet.com/tut/final/index.htm#intro>
Introduction to Volcano Web</a>
The reference marker "#anchor_name" is tacked onto the end of the URL.
Compare your web page with a sample of how this document should appear. If your web page was different than the sample or the named anchor links do not properly connect, review the text you entered in the text editor.
Example of using the link to return to section on describing the named anchor...
Review Topics
Independent Practice
Create named anchors for the headings in your own web page and build an index that will link to these sub-sections.
Coming Next....
In the next lesson you will learn how to make a picture act as a hypertext link.
| Home | Next Lesson: HyperGraphics. |
Copyright �1995-1999 by Michel Degr�ve ([email protected])