|
Tutorials | The <a> Anchor Tag
HTML: The <a> Anchor Tag
The anchor <a> tag is a container tag and requires an end tag </a> to complete its format. It is commonly used in conjunction with various attributes to create hypertext and hypermedia links to:
- a page on your Web site
- other sections of a Web page
- another Web site
- an email address
Here is how you use the <a> tag to set up a basic text link:
<a href="url">descriptive text</a>
The words "descriptive text" above, would be displayed in the browser in a different color (usually blue) and underlined, to signal it is a hypertext link.
Linking to a Page on Your Web Site
If the page you are linking to is located in the same folder or directory as the page that contains the link, you should use a relative URL and specify just the name of the Web page.
<a href="rates.html">Compare our prices</a>
However, if the Web page is in a subfolder, then the relative URL must contain the name of the folder as well as the name of the Web page.
<a herf="services/rates.html">Compare our prices</a>
Linking to Other Sections of a Web Page
This feature is useful on a Frequently Asked Questions (FAQ) page, a Table of Contents (TOC) page or a long page with different sections which you may want users to jump to quickly. Two steps are required.
- Use only letters or numbers to name (or anchor) the area of the page where you want to direct your viewers, by combining the <A> tag with the NAME attribute.
- Create a hyperlink to that particular area at the specific point you want your user to select the link.
- Create a hyperlink to that particular area at the specific point from which you want your user to select the link.
<a href="top">Top</a> (place at destination)
<a name="#top">Back to Top</a> (link to destination)
You can link to more than one section of the same page. Just make sure to give each section a different name.
A popular use for this link feature is at the end of a long Web page, to return the viewer to the top of the page.
Click for a live demonstration: Jump to Top
Linking to Another Web Site
If the HTML document you want to link to resides on a completely different Web site, you need to use an absolute URL like:
<a href="http://www.sixfigureprofits.net">Web Business Blueprint</a>
The above link will say Web Business Blueprint and will take you to the website http://www.sixfigureprofits.net
Linking to an Email Address
Creating a link to an email address is accomplished in the following manner:
<a href="mailto:comments@ebizinfocenter.com">Email Me</a>
The link will appear like this – Email Me – and when clicked will open your email program's "Write Mail" window in your browser.
Next »
|