You use hyperlinks, or simply links, to navigate to other pages in a website. A web page is a resource, and each web page has a unique identifier for people to locate the page. This unique identifier is the URL, short for Uniform Resource Locator.

What is a URL?

A URL is a web address. To locate a web page, which is a resource on the Internet, you would click on a link that contains a Uniform Resource Locator (URL) or enter one in the Address or Location box of your browser. Here are two examples of URLs:

http://google.com/index.html
http://facebook.com/index.html

 

The first part of the URLs is http, which identifies the HTTP protocol. HTTP stands for HyperText Transfer Protocol. As you may have guessed, it is a protocol for transferring web pages. Not all URLs use HTTP. For instance, these two URLs are not HTTP-based URLs:

mailto:joe@example.com
ftp://marketing@ftp.example.org

 

Absolute and Relative URLs

A URL that starts with a protocol and contains a domain, such as http://twitter.com, is an absolute URL. However, a URL can also be written without a protocol and a domain. Such a URL is called a relative URL.

Relative URLs can be found in a web page. In this case the URLs are relative to the URL of the current page. For example, if the URL of a web page is http://example.com/start.html and the page contains a relative URL named next.html, then the absolute address of next.html can be found by removing the string after the last forward slash (/) and append the relative URL. In this case, the absolute URL of next.html would be http://example.com/next.html.

There are good reasons for using relative URLs. First, relative URLs are shorter. Instead of http://example.com/next.html, you can just write next.html. More importantly, however, when you are creating a web page, you may not know exactly the name of the domain that will be used to host the web site. You cannot write an absolute URL without a domain name.

Creating A Link

You create a hyperlink using the a element. Here, a stands for anchor.

A hyperlink contains a reference to another resource and text to be displayed. The reference can refer to a resource external to the current web site or a resource in the same web site. It can even refer to a different location on the same page.

Here is an example of a hyperlink that takes the user to Google when clicked. You use the href attribute to specify a target. In this case, it is http://google.com, the Google website.

<a href="http://google.com">Search Engine</a>

 

A hyperlink that references an external resource

The text in a hyperlink can be anything but it should clearly describe the target resource. It should not be just “Click Here” or some other non-descriptive text.

The resource that a hyperlink references can be another web page or any other resource type available on the target web site. These include an image, a PDF file, a video and so on.

The download Attribute

In very rare occasions, you may want the browser to download a resource instead of trying to open it. In this case, the download attribute is what you need. For example, when the user clicks on this link, the browser will download the resource instead of opening it.

<a href="http://google.com" download>Search Engine</a>

Leave a Reply

Your email address will not be published. Required fields are marked *