Every time you click a word that takes you to another page, you are using one of the oldest and most important features of the web: the hyperlink. Links are what turn isolated pages into a connected web of information. Without them, the internet would just be a pile of separate documents with no way to move between them. For anyone learning HTML, understanding how links work is a core skill, because almost every website depends on them for navigation. In this post, we will break down how hyperlinks are built, how the anchor tag works, the difference between relative and absolute addresses, and how to jump to a specific spot within a single page.
Table of Contents
- How links connect documents on the web
- The anchor tag: building a clickable link
- Writing helpful anchor text
- Linking to email and phone numbers
- Relative and absolute URLs
- Absolute URLs
- Relative URLs
- Choosing between the two
- Linking between sections of a document
- How fragment identifiers work
- The older name attribute
- Jumping to a section on another page
- Putting it together
How links connect documents on the web
A hyperlink is a connection from one resource to another. The page you are reading is the source, and the page you land on after clicking is the destination. This simple idea is the foundation of the World Wide Web, which is why the “W” in WWW stands for “web” in the first place. Links let users move freely between related pages instead of typing a full address every time.
Links do more than just connect two web pages. According to Mozilla’s developer documentation, a link can point to web pages, downloadable files, email addresses, phone numbers, locations within the same page, or anything else that an address can describe. This flexibility is why hyperlinks are used everywhere, from navigation menus and footers to inline references inside an article.
Good linking also improves how people experience a site. When a long article has clear links to its sections, readers can jump straight to the part they need instead of scrolling endlessly. Search engines also follow links to discover and understand pages, so thoughtful linking supports both users and visibility.
The anchor tag: building a clickable link
In HTML, every link is created using the anchor element, written as <a>. The letter “a” stands for anchor. On its own, the tag does nothing useful. It needs an attribute called href, which stands for “hypertext reference,” to tell the browser where the link should go. As the W3C specification explains, the href attribute is what makes an anchor a working source for a link.
A basic link looks like this:
<a href=”https://www.example.com”>Visit Example</a>
There are three parts to notice here. The opening <a> tag marks the start of the link. The href value inside the quotation marks is the destination address. The text between the opening and closing tags, “Visit Example,” is the visible, clickable part that users see. This visible text is called the anchor text. The closing </a> tag ends the link.
Writing helpful anchor text
The words you choose for the clickable text matter. A common mistake is using vague phrases like “click here” or “read more.” These tell the user nothing about the destination. Strong anchor text describes where the link leads, such as “download the syllabus” or “view the library catalogue.” This is not just good style. People who use screen readers often pull up a list of all links on a page, so descriptive text helps everyone understand a link even when it is read out of context.
Linking to email and phone numbers
The anchor tag is not limited to web pages. By changing what goes inside href, you can create special links. Using mailto: followed by an email address opens the user’s default email program. Using tel: followed by a number lets mobile users start a call. These are handy on contact pages:
<a href=”mailto:library@example.com”>Email the librarian</a>
Relative and absolute URLs
Once you start linking, you need to understand the two ways of writing an address: absolute and relative. The choice affects how easy your site is to maintain and how reliably your links work.
Absolute URLs
An absolute URL is the complete address of a resource. It includes the protocol, such as https://, the domain name, and the full path to the file. An example is https://www.example.com/courses/html.html. Because it carries every piece of information needed to find a page, an absolute URL works no matter where it is placed. You must use absolute URLs when linking to a page on a different website, since the browser needs the full address to reach another domain.
Relative URLs
A relative URL leaves out the protocol and domain. It only gives the path to a file in relation to the current page. For example, if you are on the home page and want to link to an about page in the same folder, you can simply write:
<a href=”about.html”>About us</a>
Relative paths can also move between folders. A forward slash at the start, like /courses/html.html, points from the root of the site. Two dots, like ../images/logo.png, move up one folder level. Because relative URLs are shorter and assume the same domain, they are the natural choice for internal links between pages on your own site.
Choosing between the two
The practical rule is straightforward. Use relative URLs for links within your own website and absolute URLs for links to external sites. Relative links make a site easier to move and maintain. If you shift your whole project from a testing setup to a live server, relative links keep working without any edits, while absolute links would all need rewriting. The trade-offs between the two mean most developers mix both, picking whichever fits the situation.
Linking between sections of a document
So far, every link has moved you to the top of a new page. But sometimes you want to jump to a specific part of a page instead. This is extremely useful for long documents, single-page websites, and a table of contents. The technique is sometimes called a named anchor or, more accurately today, an in-page link.
How fragment identifiers work
Jumping to a section is a two-step process. First, you give the target element a unique id attribute. The id is a label that must be unique within the page. For example:
<h2 id=”references”>References</h2>
Second, you create a link whose href value is a hash symbol (#) followed by that same id. The hash tells the browser this is a fragment identifier, a pointer to a part of the document rather than a separate page:
<a href=”#references”>Go to references</a>
When clicked, the browser scrolls directly to the element with the matching id. As guides on in-page linking show, this is the standard way to build navigation menus for single-page sites, where each menu item points to a section further down the page.
The older name attribute
In older HTML, sections were marked using an empty anchor tag with a name attribute, written as <a name=”top”></a>. You may still come across this in legacy code. Modern HTML5 has moved away from this method. The recommended approach is to place an id attribute on any element you want to link to, such as a heading, a section, or a div. The id method is cleaner because it works on any element and does not require an extra empty tag.
Jumping to a section on another page
You can combine a page address with a fragment identifier to land on a specific section of a different page. You simply add the hash and id to the end of the URL:
<a href=”catalogue.html#fiction”>See the fiction list</a>
This opens catalogue.html and scrolls straight to the element with the id “fiction.” A popular use of this idea is a “back to top” link. By giving the top of your page an id and linking to it from the bottom, readers can return to the start of a long article with a single click.
Putting it together
Hyperlinks rest on a handful of clear ideas. The anchor tag with its href attribute is the building block. Absolute URLs carry a full address and suit external links, while relative URLs keep internal links short and portable. Fragment identifiers using id values let you move within a single page. Master these, and you can connect any set of documents into a smooth, navigable structure. Add descriptive anchor text, and your links will be useful to every reader, including those using assistive technology.
What do you think? If you were building a study-notes website with very long pages, would you rely more on in-page section links or split the content across many smaller pages? And in what situations might an absolute URL actually be safer to use than a relative one, even for an internal link?
References
- https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a
- https://www.w3.org/TR/html401/struct/links.html
- https://www.conductor.com/academy/urls/faq/absolute-vs-relative/
- https://www.dhiwise.com/post/html-relative-link-vs-absolute-whats-the-difference
- https://w3htmlschool.com/linking-to-sections-in-html-using-id-and-anchor/
- https://html5-tutorial.net/html-basics/links/

Leave a Reply