HTML Links
Links are seen mostly in all web pages. Links are used to make users click their way from page to page.
HTML Links - Hyperlinks
CompletedHTML links are considered to be hyperlinks.
By clicking on a link, you can jump to another document.
HTML Links - Syntax
CompletedIn HTML, links are always defined using the <a> tag:
Example
<a href="url">link text</a>
Example
<a href="http://daks.me">Visit
our HTML tutorial</a>
The href attribute is used to specify the destination address (http://daks.me) of the link.
The link text is the visible part (Visit our HTML tutorial).
By clicking on the link text you can go to the specified address.
Local Links
CompletedThe example used above is using an absolute URL (A full web address).
A local link (link to the same web site) is can also be specified with a relative URL (without http://www....).
HTML Links - Colors
CompletedWhen you move the mouse over a link, two things will normally happen:
- The mouse arrow will turn into a little hand
- The color of the link element will change
By default, a link will appear like this (in all browsers):
- An unvisited link is underlined and blue
- A visited link is underlined and purple
- An active link is underlined and red
You can change the default colors, by using styles:
Example
<style>
a:link {color:green; background-color:transparent;
text-decoration:none}
a:visited {color:pink; background-color:transparent; text-decoration:none}
a:hover
{color:red; background-color:transparent; text-decoration:underline}
a:active
{color:yellow; background-color:transparent; text-decoration:underline}
</style>
Try it Yourself
HTML Links - The target Attribute
CompletedThe target attribute is used to specify that the linked document should be opened at which place.
The target attribute will be having one of the following values:
- _blank - It is used to open the linked document in a new window or tab
- _self - It is used to open the linked document in the same window/tab as it was clicked (this is default)
- _parent - It is used to open the linked document in the parent frame
- _top - It is used to open the linked document in the full body of the window
- framename - It is used to open the linked document in a named frame
This example will be opening the linked document in a new browser window/tab:
Tip: If your webpage is kept locked to a frame, by using target="_top" you can break out of the frame:
HTML Links - Image as Link
CompletedIt is very common to make use of images as links:
Example
<a href="html_home.php">
<img src="smiley.gif" alt="HTML tutorial"
style="width:42px;height:42px;border:0;">
</a>
Try it Yourself
HTML Links - Create a Bookmark
CompletedHTML bookmarks are utilised for allowing readers to jump and read some other specific parts of a Web page.
Bookmarks are very useful when your webpages are very long.
For making a bookmark, you must be first create the bookmark, and then link should be added to it.
If the link is clicked, the page will be scrolling to the specified location with the bookmark.
Example
First, creating a bookmark along with the id attribute:
<h2 id="tips">Useful Tips Section</h2>
Then, adding a link to the bookmark ("Useful Tips Section"), which is done within the same page:
<a href="#tips">Visit the Useful Tips Section</a>
Or, addition of a link to the bookmark ("Useful Tips Section"), from another page:
Example
First, creating a bookmark with the required id attribute:
<a href="html_tips.html#tips">Visit the Useful Tips Section</a>
Chapter Summary
Completed- Use the <a> element for defining a link
- Use the href attribute for defining the link address
- Use the target attribute tofor defining where to open the linked document
- Use the <img> element (inside <a>) for using an image as a link
- Use the id attribute (id="value") for defining bookmarks in a page
- Use the href attribute (href="#value") for linking to the bookmark
Test Yourself with Exercises
CompletedHTML Link Tags
Completed| Tag | Description |
|---|---|
| <a> | Defines a hyperlink |
