Home / Articles / Programming languages / Markup languages / HTML & CSS / How to create a link in HTML

How to create a link in HTML

How to create a link in HTML
How to create a link in HTML
  • Currently 0 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 0/5 (0 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.

To create a link it's necessary to point to the browser where exactly it is, also to specify address of the document to link to. Both actions are performed using a tag, which has only one required parameter href. The address of the document (URL) is used as the value.

The address of the link can be absolute or relative. Absolute addresses are valid regardless of the name of the site or a web page, where the link registered. These addresses start with the data transfer protocol. So, for all web pages it's usually HTTP (HyperText Transfer Protocol), respectively, absolute links start with http:// (see example 1).

Example 1. Using absolute links.

<a href="http://www.google.com">Google search engine</a>

Relative links, as their name suggests, are constructed relative to the current document or address.

Examples of relative addresses:

These two links are called incomplete and command your web server to load file index.php (or default.php), which is located in the root folder of the site or the folder demo. If the file index.php is doesn't exist, the browser usually displays list of files in the folder.

Slash before the address means that the addressing stars from the root of the site. Link leads to picture pic.gif, which is located in the folder images. Which, in turn, is located in the root of the site.

Two periods before the name tells the browser to go one level up in the directory list.

If there are no extra characters before the name of the folder, for instance two periods, the folder is located inside the current directory (example 2).

Example 2. Use relative links.

<a href="images/xxx.jpg">Look at my picture!</a><br>
<a href="tip.php">How to make the same picture?</a>

Sometimes you can see in the link's address something like this ./file/doc.php. A period with a slash (/) this means that the link starts from the current folder. Such a entry is redundant and can be reduced to simple file/doc.php.

Read also

Parameter target in HTML

Parameter target in HTML

Image as a link in HTML

Image as a link in HTML

Links within a page in HTML

Links within a page in HTML

Discussion (total 1 comments)

farahan peerzada
January 06, 2016 at 05:29 am

Log in or create a user account to post a comment.


Quick navigation

General navigation