Sunday, 5 January 2014

Tutorial 11: HTML Links

Links are found on many web pages. These allow users to go into different sites.Also, links can be inserted in a text using HTML codes. Now lets see how its done,

HTML Hyperlinks (Links)


The HTML <a> tag defines a hyperlink.

A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document.

When you move the cursor over a link in a Web page, the arrow will turn into a little hand.

The most important attribute of the <a> element is the href attribute, which indicates the link's destination.

By default, links will appear as follows in all browsers:
An unvisited link is underlined and blue
A visited link is underlined and purple
An active link is underlined and red

HTML Link Syntax


The general syntax for a link in HTML is defined as

<a href="URL">LINK TEXT</a>

Example

<a href="http://techprojects4u.blogspot.in/">Visit Techprojects4u</a>

OUTPUT ON BROWSER:

Visit Techprojects4u

Now, if you click on the text "Visit Techprojects4u" ,then you will be directed to page http://techprojects4u.blogspot.in/ .

NOTE: The "Link text" doesn't have to be text. It can be an image or any other HTML element.



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.

EXAMPLE:

<a href="http://techprojects4u.blogspot.in/" target="_blank">Visit Techprojects4u</a>

The above code will open the link in a new tab.



Useful Note


Always add a trailing slash(/) to subfolder references. If you link like this: href="http://techprojects4u.blogspot.in/html", you will generate two requests to the server, the server will first add a slash to the address, and then create a new request like this: href="http://techprojects4u.blogspot.in/html/".




No comments:

Post a Comment