• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Links > Understanding Links

4.1. Understanding Links

A link is a snippet of computer code that gives a Web browser directions for how to get from one page to another on the Web. What makes links powerful is the fact that the distance those directions take doesn't matter. A link can just as easily lead to another page on the same site or to a page on a Web server halfway around the globe.

Behind the scenes, a simple HTML tag called the anchor (<a>) tag generates each and every link. Links come in three different flavors: absolute, document relative, and root relative. See page 94 for some examples of each link type in practice.

4.1.1. Absolute Links

When people need to mail you a letter, they ask for your address. Suppose it's 123 Main St., New York, New York 12001. No matter where in the country your friends are, if they write 123 Main St, NY, NY 12001 on an envelope and mail it, their letters will get to you. That's because your address is unique—just like an absolute link.

Similarly, every Web page also has a unique address, called a URL (most people pronounce it "You Are El"), or Uniform Resource Locator. If you open a Web browser and type http://www.sawmac.com/dwmx/index.html into the Address bar, the home page for this book opens.

This URL is an absolute link; it's the complete, unique address for a single page. Absolute links always begin with http://, and you'll use them anytime you link to a Web page outside of your own site. Absolute links always lead to the same page, whether the link to it is on a page in the current site or an entirely different site.

The bottom line: Use absolute links when you want to link to a page on another Web site.

4.1.2. Document-Relative Links

Suppose you, the resident of 123 Main Street, drop in on a couple who just moved into the neighborhood. After letting them know about all the great restaurants nearby, you tell them about a party you're having at your place.

When they ask you where you live, you could, of course, say, "I live at 123 Main St., NY, NY 12001," but your neighbors would probably think you needed a little psychiatric help. More likely, you would say something like, "Just go across the street and turn left. I'm the second house on the right." Of course, you can't use these instructions as your mailing address, because they work relative only to your neighbors' house.

When you want to create a link from one Web page to another within the same Web site, you can use similar shorthand: a document-relative link. In essence, a document-relative link—like the directions you give your neighbor—simply tells the browser where to find the linked page relative to the current page. If two pages are in the same folder, for instance, the path is as simple as "Go to that page over there." In this case, the link is simply the name of the file you wish to link to: index.html. You can leave off all that http:// and www.sawmac.com business, because you're already there.

Parts of a URL

Each chunk of a URL helps a Web browser locate the proper Web page. Take the following URL, for instance: http://www.sawmac.com/dwmx/index.html.

http— This portion specifies the protocol—the method the Web browser must use to communicate with the Web server. HTTP stands for hypertext transfer protocol. For what it's worth, HTTP specifies a connection to a Web page, as opposed to protocols like ftp (for transferring files) and mailto (for email addresses).

http://www.sawmac.com— This portion specifies the exact computer that's dishing out the Web site in question—that is, it's the address of the Web server.

/dwmx/— This is the name of a folder (sometimes called a directory) on the Web server.

index.html— This is the name of the actual document or file that the Web browser is supposed to open—the Web page itself. It's these HTML documents that Dreamweaver creates.

Document-relative links can be finicky, however, because they're completely dependent on the location of the page containing the link. If you move the page to another part of the site—filing it in a different folder, for example—the link won't work. That's why working with document-relative links has traditionally been one of the most troublesome chores for a Web designer, even though this kind of link is ideal for linking from one page to another in the same site.

Fortunately, Dreamweaver makes working with document-relative links so easy, you may forget what all the fuss is about. For example, whenever you move a page into a different folder—a maneuver that would normally shatter all document-relative links on the page—Dreamweaver quietly rewrites the links so they still work. Even better, using the program's site management tools, you can cavalierly reorganize your Web site, moving folders and files without harming the delicate connections between your site's files. Dreamweaver's site management features are discussed in depth in Part 4.

4.1.3. Root-Relative Links

Root-relative links describe how to get from one page to another within the same site, just like document-relative links. However, in this case, the path is described relative to the site's root folder—the folder that contains the home page and other pages, folders, and files that make up your site. (For a detailed description of the root folder and structuring a Web site, see Chapter 15.)

Imagine you work in a big office building. You need to get to a co-worker's office for a meeting. You call him up for directions. Now, he may not know the precise directions from your office to his, but he can tell you how to get from your building's entrance to his office. Since you both know where your building's front door is, these directions work well. Think of the office building as your site, and its front door as the root of your site.

Root-relative links always begins with a slash /. This slash is a stand-in character for the root folder—the front door—of the site. The same root-relative link always leads to the same page, no matter where it is on your Web site.

Although the principle behind them makes sense, there are some major drawbacks to using root-relative links in Dreamweaver. The most apparent is that they don't work when you test them on your own computer; clicking a root-relative link in a Web browser on your own machine produces only a "file not found" error. Such links work only after they're moved to a Web server. Web servers understand root-relative links, but your local computer doesn't.

Stick to document-relative links for your pages, but keep this discussion in mind. You'll see later that Dreamweaver's site management features use root-relative paths to track your site's files behind the scenes.

4.1.4. Link Types in Action

Figure 4-1 shows a Web site as it lies on a hard drive: folders filled with HTML documents and graphics. Here's a closer look at some links you might find on the pages there, and how they might work:

Figure 4-1. Here are a few examples of links for a fictitious Web site located at http://www.cosmofarmer.com. Notice that although the root folder (cosmo) is nested inside several other folders—book_site and missing manual—it's still the top level folder for the site, since it holds the home page and all of the other files that go on the site. Keep this distinction in mind: The site root is not the same as the top level of your hard drive. Links from the Home page (index.html) to the Subscribe page

The home-page document is usually called index.html. (The exact name depends on the configuration of your Web server. Contact your Web host, or the person in charge of your Web server, to confirm.) You could create the link from it to the subscribe.html page—identified by the number 1 in Figure 4-1—using any of the three link types:

  • Absolute. http://www.cosmofarmer.com/subscribe.html. What it means: Go to the Web site at www.cosmofarmer.com and download the page subscribe.html.

  • Document Relative. subscribe.html. What it means: Look in the same Web site and folder and download the page subscribe.html.

  • Root Relative. /subscribe.html. What it means: Go to the top level folder of this site (called cosmo, in this case) and download subscribe.html.


If you can write an absolute URL, you can easily create a root-relative URL. Simply strip off the http:// and Web server name. In the above example, erasing the http://www.cosmofarmer.com in the absolute address leaves /subscribe.html—the root-relative path. Links from the Classifieds page to the Strawberry page

Now imagine that you're building a Web page that's in a folder inside another folder. Here's how you'd use each of the three link types to open a document that's nested in a subfolder (called 2001, in this case), as identified by the number 2 in Figure 4-1:

  • Absolute. http://www.cosmofarmer.com/classifieds/2001/strawberry.html. What it means: Go to the Web site at www.cosmofarmer.com, look in the folder classifieds, and then in the folder 2001; download the page strawberry.html.

  • Document Relative. 2001/strawberry.html. What it means: From the current page, look into the folder 2001 and download the page strawberry.html.

  • Root Relative. /classifieds/2001/strawberry.html. What it means: Go to the top level folder of this site, look in the folder classifieds, and then in the folder 2001; download the page strawberry.html. Links from the Match page to the Advertise page

Now suppose you're building a Web page that's in a deeply nested folder; you want it to link to a document that's outside of its folder, a link labeled 3 in Figure 4-1:

  • Absolute. http://www.cosmofarmer.com/classifieds/advertise.html. What it means: Go to the Web site at www.cosmofarmer.com, look in the folder classifieds, and download the page advertise.html.

  • Document Relative. ../advertise.html. What it means: Go up one level—outside of the current folder—and download the page advertise.html. In links, a slash / represents a folder or directory. The two dots (..) mean: Go up one level, into the folder that contains the current folder.

  • Root Relative. /classifieds/advertise.html. What it means: Go to the top level folder of this site; look in the folder classifieds, and download the page advertise.html. The executive summary

To summarize all of this discussion: Use absolute URLs for linking outside of your site, use document-relative links for links within a site, and avoid using root-relative links altogether.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint