HTML Code For Links

Links are one of the most important things on the internet. You have two different kind of them:

  • Internal Links
  • External Links

The basic HTML code for links is <a href="URL">Clickable text</a>. Replace URL with the path to the page you want.

If you want to link to a page called "sports.html", simply put "sports.html" as your URL if the linked page is in the same folder as the page where the link is. If it's not in the same directory, you can use the URL "/../folder/page.html".

The HTML code for links to external pages is the same as for internal pages but the page path is the URL of the page you are linking to. If you want to link to http://www.computing4all.com, simply put the complete URL of the page where you would put the internal page path.

The text or image that is between the two tags will be the clickable text/image. Don't forget to add the </a> tag or the rest of your page will be clickable.

Here's an example of the HTML code for links:

<html>
<head>
<title>html code for links</title>
</head>
<body>
<a href="page.html">Click here</a>
</body>
</html>

Specifying a target for a link

When you setup a link to another page on your site, you will want it to stay in the same window but if you put a link to an external page, you might want it to open in a new page. There are several different targets for links:

  • Same window: This is default, just don't add the tag and it will go in the same window.
  • New window: "_blank"
  • Specific window: "window name" Example: If you put the target window name "games", every link with that target will open in the "games" window. When a link to that target is clicked for the first time, a new window is opened.

The HTML code for links to have a specific target is target="TARGET" where TARGET is either "_blank" or "target name".

Here's an example of a link that opens in a new window:

<html>
<head>
<title>html code for links</title>
</head>
<body>
<a href="page.html" target="_blank">Click here</a>
</body>
</html>

Back
Changing Image Size in HTML
Next
HTML Anchor Tags