. This same tag is used for external and internal links. Below is a sample:
Content for your link
- NAME gives an anchor a name. This field is optional. This attribute is usually used on longer, indexed pages or to go to a specific starting point in a different page. For a good example of named anchors, click on the link at the bottom of this page to investigate the complete(?) tag listing. If you view the source for the document, you'll notice a series of links to internal anchors for each tag listed; clicking on the tag takes you to that tag's description in the full listing.
- HREF indicates the hyperlinked reference to the other page. This can be either a local file name or an absolute path name.
If the page is on the local server in the same directory or a subdirectory from this page, you need only name the file or declare the relative location of the file from the current directory, respectively.
Example: HREF="nextFile.html" or HREF="./subdir/nextFile.html"
If the file is on the same server but located in a different directory structure, provide the absolute path to the resource on the machine.
Example: HREF="C:\Programs\Apache\htdocs\myTarget.html" or "/opt/Apache/htdocs/myTarget.html".
If the linked resource is on a remote server, provide the full path and access method.
Example: HREF="http://www.yahoo.com"
If you link to a named anchor, specify the name after the '#' sign in the URL. If the anchor is located in the current document, only the '#anchorName' is needed.
Example: HREF="#internalAnchor" or HREF="externalURL#anchorName"
- TITLE allows you to enter alternate text for the link. The content between the open and close tags for the anchor is what will actually appear on the page as the link. The title provided as an attribute inside the anchor tag may -- depending on your browser -- display as a popup tooltip when the mouse cursor is positioned over the link.
- TARGET indicates where you would like this document to appear; the default is your current browser window. Why would you want it to open elsewhere? We'll take a look at frames a little later, but to summarize, frames allow you to separate your browser into smaller sections. Each section ("frame") has a name associated with it, and documents are assigned to each section. A common use is to create a document that is nothing but a series of links to use as an index, and put actual content in several other documents that those links point to. When a frameset is created, the index is placed in one frame and each time a link is pressed, the linked document appears in the other frame, leaving the index intact. We'll look at creating frames later.
Another common use for targets is for other browser windows. You can create links that open new browser windows and name them; the "target" attribute will now cause linked documents to open in the browser window that you name. Why would you want to do this? If you've ever seen a legal document, it is filled with phrases and words that don't make a lot of sense to the common person. Each of those terms could be made into a hyperlink targeting a smaller browser window, and when the link is clicked, the definition appears in the window. The user can get a feel for what the document is about without needing to navigate away from the page. We'll take a look at this later, too.
Tips and Tricks
Something to consider when constructing your Web pages: how portable do you want the pages? For most people creating personal Web sites, you probably want to construct as many of your links as possible to be relative path names in the anchor. Why? If you change ISPs and lose access to your old server, you will need to update all links that refer to documents on that server. If your links are to local URLs, just make sure to post your pages using the same directory structure layout on the new server and everything will work as it did on the old one.
Be aware also of case sensitivity. You may be posting your pages to a Unix server or a Windows server. Windows does not care about case, so "MYDOC.html" is the same as "mydoc.html"; Unix sees those files as separate entities and may return a "404: Document not found" error. Directory structure separators on Windows-based machines are indicated by back slashes (\), whereas they are indicated by slashes (/) on Unix systems. Use whichever you wish; between your browser and the Web server, they'll figure it out. I use forward slashes in the Unix style just because it's an easier key for me to hit on my keyboard.
Give people an opportunity to tell you about broken links, but make sure that link never goes bad. How do you do that? It's a special URL trick for an anchor. Take a look at the example below:
Send me an email!
By specifying "mailto:" as the initial part of the URL and putting your email address behind it, the user is in for a treat when they click on the link. Their default mail client will start up, opening the message composer for a new mail message addressed to you. Want to be really cool about it? Try this:
Send me an email!
When you tack on the "&subject=" to the link, the subject line of the email message is filled in as well. Aren't you loving this??? Just remember that if you include a link like this so that people can rave about your site or tell you about links that aren't working, you must ensure that this link is valid!. If you change email addresses, change the link.
In the very first code sample on this page, I listed "Content for your link" between the opening and closing tags. Why didn't I say "text"? Because you can use images as well, as you'll see in the next part of this walkthrough.
So we have links, now; what's next? How would you like to add some images to your site, or maybe even figure out how to put wallpaper on your site rather than using a solid color as your background?