Skip to content

HTML for greens - HTML

What are links (hyperlinks, hypertext links) used for?

(within the same website)

Practically every website includes links (also called references or hyperlinks). Most often, a special, highlighted piece of text (or an image) serves as a link, and when you click on it, you are taken to another page. Just as every book is divided into chapters, websites typically consist of subpages. Each subpage is a separate HTML file (with the extension *.html or *.htm) and its content is usually thematically different from the others (it's created in the same way as the main page). This organization makes it easier for users to navigate and prevents unnecessary loading of the entire website at once (which would probably take a very long time). Placing everything in one file (index.html) is not recommended (unless your site is really short)!

To allow users to move freely between subpages of our website, they need to be connected in some way. You should place links to all subpages in a chosen location, typically on a separate page, which serves as a table of contents and contains links to all subpages of the site.

The syntax of a link to a subpage (within the same website) is as follows:

<a href="relative path to the subpage">link description</a>
The rules for entering the path are the same as for images.
Instead of "link description", you should enter a short text that will appear on the screen and, when clicked, will lead to the specified subpage (the address of the page is only visible in the browser's status bar).

With this type of link, you can refer to any file located on an FTP account with the website. This allows you to build a download section, i.e., links for downloading files.

Example <a href>

To see an example of how this type of link works, you can click here (it will take you to the main page of this course).

Questions and Answers

What is an online link called?

An online link is also called a hyperlink, hypertext reference, or more informally, a link. Clicking on it automatically takes you to a new page it points to.

How to Create a Link to an HTML Subpage?

For example, if the file of the subpage is named "contact.html" and it's located in the same folder on your computer's disk as the *.html document in which you want to insert the link, you can use the following tag: <a href="contact.html">...</a>.

Why Doesn't the Link Work?

The most common reason for a non-functional link on a website is typographical errors in the file name of the link's subpage or an incorrectly constructed path [see: Inserting an Image]. Another reason might be omitting the file extension, either *.html or *.htm. Although in some operating systems (e.g., Windows) file extensions may be hidden, when inserting a link to a subpage, you always need to specify it. The link might not work if the file name of the subpage includes forbidden characters, such as diacritical Polish letters or spaces. It is also recommended not to use capital letters. If the link doesn't work at all, it might be due to a typographical error in the tag name or attribute - it should be written correctly, for example: <a href="subpage.html">...</a>.