ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Computer Programming Tutorials

How to Use Simple HTML Programming to Make a Link

Updated on May 12, 2013

HTML

Hyper Text Markup Language
Hyper Text Markup Language

What is HTML?

Hyper Text Markup Language or HTML as it is known to everyone is the main programming language used to create web pages and websites that are displayed on web browsers.

A markup language is a language that consists of a set of markup tags. These tags describe the content of the document.

HTML documents consists of these markup tags (HTML tags) and plain text. HTML documents (documents saved in the .html or .htm format) are known as webpages.

Sample HTML code: Copy-paste the following html code in Notepad and save it as test.html

<html>
<head>
<title>This is my First Webpage</title>
<h1>This is my heading</h1>
</head>
<body>
<p>This tag is used to format your text as a Paragraph</p>
<b>This tag makes your text bold</b>
<br> This tag takes you to the next line
<br><b> Congratulations on your First Successful Link</b>
</body>
</html>

What are HTML tags?

  • HTML tags are tag names enclosed in angle brackets(<>). Example: <html>
  • HTML tags usually consists of two pairs, the being known as the opening (or start) tag and the second, the closing (or end) tag. Example: <head> </head>
  • The end tag is exactly the same as the start tag except for a forward slash ( / ) before the tag name.

What is a Hyperlink?

A Hyperlink is basically any word, alphabet, group of words, text or even an image, used as a link that when clicked on re-directs you to a new webpage or document.

When your on a webpage if you move the cursor over a link, your cursor will turn from the arrow into a little hand with it's index pointing at the link. Place your cursor here to observe this.

HTML Link Syntax

<body>
<a href="url">Visible text which will be used as the link</a>
</body>

Basic and Simple HTML Link Syntax:

A Hyperlink or link in HTML is defined by the <a> tag, also known as an anchor tag.

An important attribute of the anchor tag ( <a> ) is href, which is a reference and indication (in simple words the address) of the link's destination.

The text that comes between the anchor tags( <a> text </a> ) is the anchor text, that is the link specified in the attribute href will get anchored to this text creating the link.

By default in all browsers links appear as follows:

  • An unvisited link is shown as underlined and blue in color.
  • A visited link (a link you have visited already previously) is underlined and purple in color.

  • An active link (a link that you have just clicked on) is underlined and red in color.

Simple Tutorial To Learn To Use Links In HTML:

  1. Open Notepad and copy paste the sample code provided above.
  2. Click Save.
  3. Name the file as Test.html and save it on your D drive (not in any folder, this will help in getting a simple URL address).
  4. Open a new Notepad file and copy paste the code given below.
  5. Save the file as Test2.html.
  6. You may save this file on your Desktop.
  7. You will now see your file Test2 on your Desktop with the Internet Explorer icon (or which ever is your default browser). This is because saving it as .html converts it into a Webpage.
  8. Double click and open Test2.
  9. You will know see the text "My First Link" in blue and underlined. Move your cursor over it and it'll turn into a little hand, showing you that it is a link.
  10. Click on it and it should re-direct you to your previous Webpage saved on your D drive, that is Test1.

Congratulations, you have just created your first HTML Webpages with links in them!

Sample Link Code: Copy-Paste the following html code and save it as Test2.html

<html>
<head>
<title>My Second Webpage</title>
</head>
<body>
<b>Let's create a Link</b>
<br>
<a href="D:\Test.html">My First Link</a>
</body>
</html>

Opening the HTML Linked Page in a New Window:

As you probably realized after trying out the above tutorial, that when you click on the link, the current page is closed and the next page opens in it's place.

In order to prevent this from happening, for instance when your putting a link to some other website within your website, you wouldn't want the other site to open up in place of yours. There are few chances of the user clicking on the back button and even if the user does so, it's annoying for him to keep going back and forward.

So a simple solution would be to open the link in a new window or tab.

The code given below is used to open the link in a new window:

target="_blank"

An example of how to implement this code is as follows..

You may substitute it for the previous link code in the tutorial file "Test2.html" and see how it works.

Syntax for Opening a HTML Link In a New Window :

<a href="D:\Test.html" target="_blank">My First Link</a>

Use An Image As A HTML Link:

We have seen above how to create links using text as an anchor..

We will now try and use an image as an anchor, that is, when you click on the image, it will re-direct you to the destination ( another website or webpage ) that you desire.

Syntax for Using An Image as a HTML Link:

<body>
<p>Click on the Image:
<a href="D:\Test.html"><img border="0" src="test.jpg" alt="Testing an image link" width="auto" height="auto"></a>
</p>
</body>

HTML Image Link Syntax Explaination:

In the above code, instead of putting text inside the anchor tags ( <a> </a> ), we have put the code to insert an image within the tags.

In the image insertion code, I have put the border as equal to 0, so has to leave your image without a border (if your image is a circle, it'll get a square border by default).

The width and height has been set to auto, so that it'll take the original width and height. (You can even remove the width and height from the code if you desire to do so)

Testing the HTML Image Link Code:

  1. Before testing the code, save an image on your desktop or where ever you have saved your Test2.html file.
  2. Rename the image as test.jpg.
  3. Now copy the syntax ( only the code between the body tags and not the body tags as well).
  4. Paste the code within the body tags of your Test2.html file.
  5. Save and open the file and check if it works.

© 2013 Paiva

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.