Monday 17 September 2012

HTML Links

You must have observed a webpage is fully loaded with links that connect to other pages and websites.
So, how do we do this?


HTML Hyperlinks (Links)

A hyperlink (or link) is a word, group of words, or image that you can click on to jump to a new document or a new section within the current document.
When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
Links are specified in HTML using the <a> tag.
The <a> tag can be used in two ways:
  1. To create a link to another document, by using the href attribute
  2. To create a bookmark inside a document, by using the name attribute



HTML Link Syntax

The HTML code for a link is simple. It looks like this:
<a href="url">Link text</a>

HTML Links - The target Attribute

The target attribute specifies where to open the linked document.
The example below will open the linked document in a new browser window or a new tab:
<a href="www.techoyo.blogspot.com" target="_blank">Visit TechoYO!</a>


HTML Links - The name Attribute

The name attribute specifies the name of an anchor.
The name attribute is used to create a bookmark inside an HTML document.
Note: The upcoming HTML5 standard suggests using the id attribute instead of the name attribute for specifying the name of an anchor. Using the id attribute actually works also for HTML4 in all modern browsers.

A named anchor inside an HTML document:
<a name="tips">Useful Tips Section</a>



Create a link to the "Useful Tips Section" inside the same document:
<a href="#tips">Visit the Useful Tips Section</a>

You must have seen that this is the way parts are linked in wikipedia.


Image as a link

Try this code:

<!DOCTYPE html>
<html>
<body>

<p>Create a link of an image:
<a href="www.techoyo.blogspot.com">
<img src="smiley.gif" alt="HTML tutorial" width="32" height="32" />
</a></p>

</body>
</html>

Creating mail link

Try this code:

<!DOCTYPE html>
<html>
<body>
<p>
This is an email link:
<a href="mailto:someone@example.com?Subject=Hello%20again">
Send Mail</a>
</p>
<p>
<b>Note:</b> Spaces between words should be replaced by %20 to ensure that the browser will display the text properly.
</p>
</body>
</html>

No comments:

Post a Comment