HTML links
Links are used to create connections to other documents and other resources such as images or sound files on the world wide web.
This lesson focuses on:
- The <a> tag
The <a> tag
The <a> (anchor) tag is the tag used to create links on a webpage.
Attributes of the <a> tag:
-
href
The href attribute denotes the webpage or resource to link to.
Syntax:
<a href="url">text that will be displayed as the link</a>
This example will link to www.google.com:
<a href="http://www.google.com">google.com</a>
Output:
Clicking on the link will take you to www.google.com
-
target
The target attribute denotes where a link will open. By default, it will open in the same window, but you can set it to open in a new window by setting the target attribute to "_blank"
Example:
<a href="http://www.lycos.com" target="_blank"> Check out the Lycos search engine! </a>
Output:
Clicking on the link will open www.lycos.com in a new window.
-
name
The name attribute denotes a specific part of a webpage to jump to - a named anchor.
Syntax for a named anchor:
<a name="anchor_name">text that will be displayed</a>
To link to a named anchor, add a # symbol and the name of the anchor to the end of a URL.
Example:<a href="http://www.somewebsite.com/files/file1.php #data"> See the data </a>
This example will jump to the 'data' section on the page located at www.somewebsite.com/files/file1.php. The named anchor at the 'data' section would look like this:
<a name="data">Data</a>
You can also link to an anchor from within the document where the anchor is located. For example, a link to the 'archive' section on the page located at www.somewebsite.com/files1/file.php would look like this:
<a href="#archive">See archive</a>
The named anchor at the 'archive' section would look like this:
<a name="archive">Archive</a>
Examples
Linking to other websites
This example demonstrates linking to other websites.
Linking to pages in other directories
This example demonstrates linking to pages in other directories.
Exercises
Create a page that links to various search engines (google, yahoo, altavista, lycos, etc). [Click here to see solution]
Create a page that links to five different pages on different websites that should all open in a new window. [Click here to see solution]




