Linking to other documents
To link to a file on a Web server, your HTML tag would look like:
<a href="http://www.ncsu.edu/">Welcome to NCSU</a>The text that appears between the beginning and ending tags ("Welcome to NCSU" in the above example) is the text that is the link the reader clicks on to go to that URL.
When you make a link, imagine you're creating two anchor points: one exists in your document (the text to click on), while the other is the document to which you're linking. You basically create a thread between two points.
Here are what the parts mean:
<a -- starts the anchor href -- stands for "hypertext reference" http://www.ncsu.edu/ -- the URL of the other document Welcome to NCSU -- the text that will appear and be clickable /a> -- ends the anchorAs long as you know the URL for a file, you can create a link to it.
Continuing on with the above example. We are creating a link from the top of "chapter2.html" to the fourth paragraph; we are going to call this link "important". First, you would define the name "important" in the fourth paragraph with the name tag
<a name="important">First sentence in fourth paragraph</a>Next, create the link to this "important" anchor (at the start of "chapter2.html"). It would look like:
<a href="#important">link to important stuff</a>The pound sign in front of the anchor name tells the browser to look for the link inside the document already loaded instead of looking elsewhere in another file.
Note that anchor names are case sensitve, and that some kind of non-blank text must appear in the named anchor tag.
First, you set up a named anchor in the document you are linking to (chapter2.html). To do this, go to the section in your second document where you want the reader to begin and define a named anchor. Name this anchor "important". Insert the following tag in the appropriate place in the second document:
<a name="important">some text</a>Now to create the link in your first document. In your first document you need to include not only the file name, but the name you defined for the anchor. This named anchor is separated from the file name by a pound sign (#). Place this tag where you want the link to show up (the highlighted text).
<a href="http://www.here.edu/chapter2.html#important">important part</a>A user would see that the first document has the words "important part" highlighted. Clicking on this highlighted text would take them to the "important" section in the second document.
The same concept works with URL addresses. When linking from one document to another in the same directory, only the second document name is necessary, not the entire URL. For example
<a href="second_doc.html">Go to next page</a>You can also link across directories to a document by relative position. For example
<a href="../third_doc.html">Go to third page</a>links to a document in one directory hierarchy higher than the current document.
Relative links are strongly encouraged as they are easier to type and allow you to move groups of files from one machine to another without editing the files at all. Naturally though, relative linking becomes more and more dangerous the more directories you traverse. With that in mind, it's usually best to use relative linking only within files that are part of a single project (such as this HTML tutorial).