Links are created in HTML with the <A>...</A> tag, commonly referred to as the anchor tag. Before creating a link two things must be known:
The most common attributes of the <A>...</A> tag are
The HTML code for a link is shown and broken down below:
Example: Basic Use Of HREF Attribute |
---|
<A HREF="Links.html">Link to the top of this example</A>
____________</Example> |
Result: |
---|
Link to the top of this example
____________</Result> |
Breaking it down, the parts of the link are as follows:
Often linking to a specific file is not specific enough. Linking to a specific place in the BODY of an HTML page can be done with the NAME attribute.
Result: |
---|
Jump to the AnchorPoint in the Links.html file
All the reader sees is the line above ____________</Result> |
The complete example to break down is in two parts:
Any text can be used in place of the AnchorPoint example. The type must match exactly in both the source (<A HREF=...>) and target (<A NAME=...>) tags.
If linking to a different point in the same file, the name of the target file may be omitted in the source, starting the name of the link with the Pound Sign:
<A HREF="#AnchorPoint">Link To It</A>
Anything between the opening (<A HREF="...">) and closing (</A>) anchor tags will serve to activate the link whether it is text or a graphic element.
Simply adding code for an image inside the anchor tags will work:
Example: Using An Image As A Link |
---|
<A HREF="Links.html"><IMG SRC="Image.gif"></A>
____________</Example> |
Result: |
---|
____________</Result> |
As a Web presentation grows and dozens or hundreds of files are needed, it becomes necessary to organize themm in folders or directories.
When HTML files that are not in the same folder or directory are referenced, the link must contain instructions leading the browser to the location of the file. HTML allows links to be made using absolute and relative pathnames.
Absolute pathnames specify the exact location of the file using the names of the directories that must be traversed in order to reach the referenced file.
Absolute pathnames are not nearly as portable as relative pathnames. If files move to a different folder or directory, or if part of a path or disk is renamed, absolute pathnames will not work. The link will be broken and the files will not be found.
Example: Absolute Addressing (1) |
---|
<A HREF="d:/HTML/index.htm">
The file index.htm is located on Drive D: in the HTML directory ____________</Example> |
Example: Absolute Addressing (2) |
---|
<A HREF="Server/HTML Stuff/index.html">
The file index.html is located on the "Server" in the "HTML Stuff" folder ____________</Example> |
Relative pathnames are the best way to keep your document portable. If the files are moved from one disk to another, or pushed several directories down, the links still work.
The browsers remembers where the first file was opened; when another is called, it begins searching from the same directory as the file it already has open.
Example: Relative Addressing (1) |
---|
<A HREF="file2.html">
Look for "file2.html" in the same directory as the current file ____________</Example> |
Example: Relative Addressing (2) |
---|
<A HREF="../file2.html">
Look for "file2.html" one level up from the current directory (two periods and a slash) ____________</Example> |
Example: Relative Addressing (3) |
---|
<A HREF="../../file2.html">
Look for "file2.html" two levels up from the current directory (two periods and a slash, once for each directory) ____________</Example> |
Example: Relative Addressing (4) |
---|
<A HREF="morefiles/file2.html">
Look for "file2.html" one level down from the current directory in the "morefiles" directory ____________</Example> |
Example: Relative Addressing (5) |
---|
<A HREF="../../Specials/Pricing/file2.html">
This time "file2.html" will be found two levels up, and then down in the directory structure into the "Specials" directory then the "Pricing" directory ____________</Example> |
URL stands for Uniform Resource Locator. Simply, it is a method to point to a specific place on the Internet. It allows each place to have a unique "address", like a street address or phone number. Each URL contains 3 parts: