Home > Articles > Programming > Web Services/ XML/ SOA/ WebSphere/ WCF

Introduction to HTML: Linking to Other Web Pages

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close Window

Michael MorrisonDick Oliver

Learn more…

Sorry, this author hasn't written any articles.

Sorry, this author doesn't have anything for sale.

Sorry, this author hasn't posted any blogs.

Without links, your page is an island unto itself, with no connection to anything else. To make it a "real" web page, you need to connect it to the rest of the World Wide Web—or at least to your own personal or corporate web of pages. This hour shows you how to create hypertext links to connect your page to the world.

In the previous two hours you learned how to use HTML tags to create a web page with some text on it. However, at this point the web page is an island unto itself, with no connection to anything else. To make it a "real" web page, you need to connect it to the rest of the World Wide Web—or at least to your own personal or corporate web of pages.

This hour shows you how to create hypertext links. You'll learn how to create links that go to another part of the same page in Hour 6, "Creating Text Links."

Hypertext links are those words that take you from one web page to another when you click them with your mouse.

Although the same HTML tag you study in this hour is also used to make graphical images into clickable links, graphical links aren't explicitly discussed here. You'll find out about those in Hour 8, "Putting Graphics on a Web Page." For now you'll focus your energy on linking to other pages via words, not graphics.

Linking to Another Web Page

The tag to create a link is called <a>, which stands for "anchor." While the word "anchor" might seem a little obscure when describing links, it has to do with the fact that you can use the <a> tag to identify a particular spot within a web page—an anchor point. Granted, there are certainly better words out there that would make more sense, but we're stuck with "anchor" so just go with it! Within the <a> tag, you put the address of the page to link to in quotes after href=, like the following:

<a href="http://www.stalefishlabs.com/products.html">click here!</a>

This link displays the words click here! in blue with an underline. When a user clicks those words, she sees the web page named products.html, which is located on the web server computer whose address is http://www.stalefishlabs.com—just as if she had typed the address into the web browser by hand. (By the way, Internet addresses are also called Uniform Resource Locators, or URLs, by techie types.)

Getting back to the <a> tag, href stands for "hypertext reference" and is an attribute of the <a> tag. You’ll learn more about attributes in Hour 5, "Basic Text Alignment and Formatting."

An attribute is an extra piece of information associated with a tag that provides further details about the tag. For example, the href attribute of the <a> tag identifies the address of the page to which you are linking.

Listing 3.1 includes a few <a> tags, which show up as underlined links in Figure 3.1. The addresses for the links are given in the href attributes. For example, clicking the words Times Square in Figure 3.1 will take you to the page located at http://www.earthcam.com/usa/newyork/timessquare/ as shown in Figure 3.2.

Listing 3.1 -<a> Tags Can Connect Your Pages to Interesting Locations

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
  <title>You Aren’t There</title>
 </head>

 <body>
  <h1>Wonders of the World</h1>
  <p>
   Vacations aren’t cheap. But who needs them anymore, with so many live
   cameras connected to the World Wide Web? Pack a picnic, and you can
   visit just about any attraction you want without ever spending any gas
   money or boarding a plane. Stop off at
   <a href="http://www.earthcam.com/usa/newyork/timessquare/">Times
   Square</a> in New York City to see a live view of the busy spot. Then
   head south to Atlanta, Georgia and watch the
   <a href="http://www.atlantafalcons.com/fans/article.jsp?id=6947">Atlanta
   Falcons training camp</a> live online. When you’re finished watching
   Michael Vick, head out west to one of my favorite destinations and take
   in the incredible red rocks of
   <a href="http://www.earthcam.com/cams/arizona/sedona/">Sedona,
   Arizona</a>.
  </p>
 </body>
</html>
Figure 3.1

Figure 3.1 The HTML in Listing 3.1 produces this page, with links appearing as blue or purple underlined text.

Figure 3.2

Figure 3.2 Clicking the Times Square link in Figure 3.1 retrieves the live Times Square Earth Cams page from the Internet.

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on November 19, 2009 No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network