Creating A Text Link

How can I create a link to another page?

The anchor tag is what you use to create links to other documents on the World WIde Web. Pretty simple huh? Not always.

The anchor tag is written like this:

<A> and </A>

Notice the anchor requires both the Opening <A> Tag and the Closing </A> Tag.

However, if you used the tag above as written, it would do absolutely nothing for you, since anchors rely on Attributes to be of any use to you. Anchors need the HREF= (Hypertext Reference) attribute to work properly.

<A HREF=> </A>

The above is a very basic link tag. Unfortunately it is incomplete and will do nothing until we give it a place to link to. This is done by completing the HREF= attribute like this:

<A HREF="http://www.gazoo.net"> </A>

The quotes are ABSOLUTELY NECESSARY. You must have them there or the anchor link will not work. By putting a web address in quotes, you are telling the HREF= attribute what address to use.

Now, if you put the above example on a web page, it won't work. Why? Because you have assigned nothing to click on. You have defined the tag you want to use, and the action you want the tag to do, but we still need a way to activate the tag on a web page. We do this simply by putting some text between the opening and closing tag, like this:

<A HREF="http://www.gazoo.net">Gazoo's Gold</A>

Now the text is clickable and usable, because you have defined each part of the anchor tag correctly. You have told it that it is an anchor by using the <A, then you told it to use the HREF= attribute, then you told it to use "http://www.gazoo.net"> as the reference to link to, then you gave the linked reference a definition to click on by putting Gazoo's Gold between the tags, and finally you completed the tag by closing it with </A>

Now... here is where it gets a little tricky. The above example is what is known as an ABSOLUTE reference. You are giving the full and complete web address to the tag, so it will know exactly where to go.

However, there is another type of reference called a RELATIVE reference that can be very handy and time saving when you are coding YOUR OWN pages. RELATIVE references only work if the pages you are linking to are contained in the same place as the referring page.

Confusing huh?

Let's pretend I am coding my index page (index.html) and I want to link to a page (let's call it pagetwo.html) in the SAME DIRECTORY on MY site. If we used the ABSOLUTE method as shown above, I would code the link like this:

<A HREF="http://www.gazoo.net/pagetwo.html"> Page 2 </A>

Then if I clicked on "Page 2" it would send me there.

Using the RELATIVE reference though, you can define a page without having to use the "http://www.gazoo.net" part because it already exists in the current directory (same directory as the referring page, in this case my index.html) on YOUR SERVER, like this:

<A HREF="pagetwo.html"> Page 2 </A>

Now, if that isn't confusing enough lets pretend I have a folder called 'humor' on my server for humor pages and I want to use a RELATIVE REFERENCE to link to a page in my humor folder:

<A HREF="humor/pagetwo.html"> Humor Page 2 </A>

The link is defined RELATIVE to the REFERRING page (the page you are creating the link on).

Yeah I know, it takes a little getting used to. RELATIVE references are handy though, because it saves having to type the full and complete URL to every page on YOUR site when you are creating links within your own pages.

As a beginner it is probably just as easy to use the ABSOLUTE method, but a little knowledge never hurt anyone..:)

Try both on your site, and see if you can master both ABSOLUTE and RELATIVE methods!


Return to the Tutorial Menu HTM-Hell: HTML For Newbies
Email: webmaster@gazoo.net

  Design and Tutorials by Gazoo, Infinity International ©1998  

Click Here!