Lessons | previous | next |

8. Linking it with Anchors

What is a URL?

The real power of the web is the ability to create hypertext links to related information. That other information may be other web pages, graphics, sounds, digital movies, animations, software programs, contents of a file server, a log-in session to a remote computer, a software archive, or and "ftp" site.

The World Wide Web uses an addressing scheme known as URLs, or Uniform Resource Locators (sometimes also called "Universal Resource Locator"), to indicate the location of such items. These hypertext links, the ones usually underlined in blue, are known as anchors (This should not be news to you as you followed several to get this far!).

Wow! That sounds like a lot to do! Don't worry -- it is no more complex than what you have done up to this point.

After all, without the hypertext, we would be only calling this "Writing TML" and not Writing HTML


8a. Linking to Local Files

Link to Local Files

The simplest anchor link is one that opens another HTML file in the same directory as the presently displayed web page. The HTML format for doing this is:


     <a href="filename.html">text that responds to link</a>

Think of it as "a" for anchor link and "href" for "hypertext reference".

The filename must be another HTML file. Whatever text occurs after the first > and before the closing </a> symbols will be the "hypertext" that appears underlined and "hyper."

Now follow these steps to build an anchor link in your HTML document to a local file:

  1. Open your HTML document, volc.html, in the text editor.
  2. First, under the Volcanic Places in the USA heading, enter the following text which introduces the two volcanoes discussed in later sections.
    
         Listed below are two places in the United States that are 
         considered "active" volcanic areas.
  3. Below the "Mount St. Helens" heading, enter:
    
         On May 18, 1980, after a long period of rest, this quiet
         mountain in Washington provided <a href="msh.html">
         detailed observations</a> on the mechanics
         of highly explosive eruptions.
    The text "detailed observations" will link the viewer to a second HTML document called msh.html. This second HTML file does not yet exist; we will construct it in steps (5) and (6).
  4. Save and close your HTML document
  5. Now, with your text editor, open a window for a New document.
  6. Enter the following text in the new window:
    
         <html>
         <head>
         <title>Mount St Helens</title>
         </head>
         <body>
         <h1>Mount St Helens</h1>
         The towering pine trees of this once-quiet mountain 
         were toppled over like toys.
         </body>
         </html>
    
  7. Save this file as msh.html in the same directory/folder as your working HTML file (volc.html).
  8. Reload volc.html in your web browser.
  9. Test the hypertext link for the words "detailed observations". When selected, it should connect you to the new page about Mount St. Helens.

Anchor Link to a Graphic

In lesson 7, we learned how to display an "inline" graphic that would appear in your web page. With the anchor tag, you can also create a link to display a graphic file. When the anchor link is selected, it will download the image file and display the image by itself in an empty page.

The simplest anchor link is to a file in the same directory/folder as the document that calls it. The format for creating a hypertext link to a graphic is the same as above for linking to another HTML document:


  <a href="filename.gif">text that responds to link</a>

where filename.gif is the name of a GIF image file.

Now follow these steps to add a link to a graphic file in your HTML document:


     The towering pine trees of this once-quiet mountain 
     were <a href="msh.gif">toppled over like toys</a>.
  • Save the msh.html file and Reload in your web browser
  • Now click on the link you just created in step (3).
  • A picture of blown down trees should be displayed.
  • 8b. URLs: Pointers to the Internet

    What is a URL?

    The Uniform Resource Locator (URL) is what the WWW uses to find the location of files and documents from computers on the Internet. On your web browser screen, the URL for this document is typically displayed in the upper part of the Web browser window. The URL includes:

    The URL is what you will need to build a link from the web page that you are creating to connect to some other piece of information available on the Internet. For more information, see Curling Up To URLs (v0.2)

    How are URLs Structured?

    The structure of a URL is:
        type://in.ter.net.address/directory/sub-directory/.../filename

    The "type" indicates the type of Internet server being accessed:

    http
    a web server, "HTTP" stands for HyperText Transfer Protocol

    gopher
    an Internet Gopher site or menu driven directories of files and information

    ftp
    an anonymous File Transfer Protocol (FTP) site, archives of files.br>
    telnet
    initiates a Telnet session to log on remotely to another computer When selected, your web browser will launch a Telnet external program and connect to the specified site.

    WAIS
    Wide Area Indexed Server -- a site to search a collection of subject oriented documents by keywords

    file
    A file on your local computer system (hard drive, floppy, local file server)

    The type is always followed by "://" and the Internet address of a remote computer. This is in the structure of:

         host.domain.domain.domain

    For example:

         machine.department.college.edu
         123.45.6.78
         office.company.com
         agency.branch.gov
         machine.organization.country     
    

    If the URL is to the main level of this host (its "home page"), then the URL is terminated with a slash "/". If you are linking to a sub-directory or a file, you must also add the exact path to that item using the slash character to indicate the entire file path.

    Note: For most web servers spelling does count! So does capitalization! File names on UNIX computers are case sensitive, meaning that a file named
         SpiffyText.html
    is a different file than
         spiffytext.html

    Experimenting With URLs

    Note that URLs can link to any site, directory, subdirectory, text file, image, digital movie, or sound file on any Internet site that is set up for public access. The best way to see different URLs is just to move your mouse over any hypertext link in any web page -- if you look at the bottom of your web browser, it should display the URL that you would connect to if you clicked on that link. You could go to a big site such as Yahoo and "peek" at URLs (did you see the URL for Yahoo when you moved your mouse over the link in the this sentence?)

    Here is an easy way to copy a URL for a link in any page. You first must access the "secret" pop-up menu from any hypertext link in a web page -- click and hold the mouse for Macintosh; click the right mouse button for Windows and Unix. From this menu, select Copy This Link Location (or similar menu item). After releasing the mouse button, jump to any text document and select Paste from the Edit menu. Voilà! You've just nabbed a URL from a link in the web page (this way, you can copy a URL without even visiting the page it links to!)


    8b. URLs: Pointers to the Internet

    URL? Earl? Yurl? hurl? gyrl?
    It's getting time to link to that Big Wide Web using the web's addressing scheme.


    What is a URL?

    The Uniform Resource Locator (URL) is what the WWW uses to find the location of files and documents from computers on the Internet. On your web browser screen, the URL for this document is typically displayed in the upper part of the Web browser window. The URL includes:

    The URL is what you will need to build a link from the web page that you are creating to connect to some other piece of information available on the Internet. For more information, see Curling Up To URLs (v0.2)

    How are URLs Structured?

    The structure of a URL is:
        type://in.ter.net.address/directory/sub-directory/.../filename

    The "type" indicates the type of Internet server being accessed:

    http
    a web server, "HTTP" stands for HyperText Transfer Protocol

    gopher
    an Internet Gopher site or menu driven directories of files and information

    ftp
    an anonymous File Transfer Protocol (FTP) site, archives of files.br>
    telnet
    initiates a Telnet session to log on remotely to another computer When selected, your web browser will launch a Telnet external program and connect to the specified site.

    WAIS
    Wide Area Indexed Server -- a site to search a collection of subject oriented documents by keywords

    file
    A file on your local computer system (hard drive, floppy, local file server)

    The type is always followed by "://" and the Internet address of a remote computer. This is in the structure of:

         host.domain.domain.domain

    For example:

         machine.department.college.edu
         123.45.6.78
         office.company.com
         agency.branch.gov
         machine.organization.country     
    

    If the URL is to the main level of this host (its "home page"), then the URL is terminated with a slash "/". If you are linking to a sub-directory or a file, you must also add the exact path to that item using the slash character to indicate the entire file path.

    Note: For most web servers spelling does count! So does capitalization! File names on UNIX computers are case sensitive, meaning that a file named
         SpiffyText.html
    is a different file than
         spiffytext.html

    Experimenting With URLs

    Note that URLs can link to any site, directory, subdirectory, text file, image, digital movie, or sound file on any Internet site that is set up for public access. The best way to see different URLs is just to move your mouse over any hypertext link in any web page -- if you look at the bottom of your web browser, it should display the URL that you would connect to if you clicked on that link. You could go to a big site such as Yahoo and "peek" at URLs (did you see the URL for Yahoo when you moved your mouse over the link in the this sentence?)

    Here is an easy way to copy a URL for a link in any page. You first must access the "secret" pop-up menu from any hypertext link in a web page -- click and hold the mouse for Macintosh; click the right mouse button for Windows and Unix. From this menu, select Copy This Link Location (or similar menu item). After releasing the mouse button, jump to any text document and select Paste from the Edit menu. Voilà! You've just nabbed a URL from a link in the web page (this way, you can copy a URL without even visiting the page it links to!)


    8c. Links to the World: Internet Sites


    HTML for Anchors to the Internet

    Linking to a site on the Internet combines what we have worked on earlier in the lessons on Links to Local Files (previous Lesson 8) by incorporating what we have learned about URLs before). The full HTML format for an anchor link to an item on the Internet is:

    
         <a href="URL">Text to Activate Link</a>
    

    where URL is the full Uniform Resource Locator, in quotes, the address for the Internet site where you want to send the viewer. The string Text to Activate Link is what will show up as hypertext in your web browser (usually but not always) underlined and in blue. When a viewer clicks on this hypertext, the web browser will link them to the Internet site indicated by the URL. Remember that a URL can be a link to another World Wide Web (WWW) server, Gopher server, FTP site, or any text, graphic, sound, video file on these servers.

    A Quick 'n Easy Way to Enter URLs in Anchor Tags

    As you navigate among different web pages, the URL of the currently visible page can be viewed at the top of the web browser window (You may have to look for a menu option to Display URLs). For example, in this document, the URL looks something like:

    
       http://www.mcli.dist.maricopa.edu/tut/tut8c.html
    

    You can use your mouse to select and copy a URL from the web browser display and then paste it in the anchor tag of your HTML document. This is much more efficient than writing URLs down on paper (some are quite long!).

    Now we will add some links to other sites that we will list under the References section of our Volcano lesson. One such site that might offer relevant information is the US Geological Survey.

    Follow these steps:

    1. Open your HTML document index.html in the text editor
    2. Under the heading "References", enter:
      
      <ul>
      <li> <a href="">Educational Resources from the
      USGS</a>
      </ul>
      
      NOTE: We've constructed the hypertext link but we still need to enter a URL between the quotes.
    3. Connect to the US Geological Survey Education Index.
    4. From the web page, use the mouse to Select the URL as displayed in the URL display field.
    5. From the Edit menu, Copy the URL.
    6. Now, return to your HTML document index.html
    7. Click the mouse once between the two quote marks you inserted in step #2 and Paste the text you copied in step #5. The final anchor tag should look like:
      
      <a href="http://info.er.usgs.gov/education/index.html"> 
      Educational Resources from the USGS</a>
      
      Note: You have just set up the HTML structure for an Unordered List, with each list item a hypertext link to a site that offers information about volcanoes. For a review of lists, see lesson 6

    8d. Links to Sections of a Page

    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 if it is long, 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. When you get there look for a link that will return you to this very spot.

    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 previous on lesson 8.

    Writing a Link to a Named Anchor

    When you want to create a 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.

    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.
  • Save and Reload into in your web browser.
  • 8e. HyperGraphics

    A HyperLink Button

    The way to do this is to put the HTML tags for inline images within the hypertext portion of the anchor tag:

    
       <a href="fileX.html"> <img src="graphic.gif">
       Go to Document X</a>
    

    In your web page, this HTML code will display an inline image and the text Go to Document X. Both will act as hyperlinks; clicking on either the text or the picture will tell your web browser to go to the HTML file fileX.html. The image alone could be a hyperlink. In the World Wide Web, a "HyperGraphic" generally is surrounded by a colored box matching the color of hypertext on your web page, so you know that it is "active".

    NOTE: Many browsers now can alter the color of hypertext and some pages have suppressed the display of the outline around HyperGraphic links. Generally, you can identify a hyperlink area on a web page by looking for a change in the cursor as it passes over a "hot" region. The cursor usually changes from an arrow to a hand when it passes over an active link.

    From a design standpoint, we recommend that if you use pictures to act as hyperlinks that you offer also a text link or use the ALT= attribute in the <IMG...> tag in case the viewer has turned off the loading of images.

    Lesson Index | previous: "Leeson 7" | next: "Preformatted Text" |