In the world of web development, hyperlinks are an essential component of navigating from one web page to another. Knowing how to add a hyperlink in HTML code is as fundamental as understanding HTML itself.

Hyperlinks are embedded with anchor, or anchor tag, inside HTML. They help to transfer the user from one HTML page to another with a single click. This guide will simply that for you.

Creating a Simple Hyperlink
A basic hyperlink can be created by enclosing the 'a' tag around the text, and providing a link with 'href' attribute. The 'href' attribute contains the web address you want the link to visit. Like so:

<a href="https://www.example.com">Click here</a>
Using Absolute URLs

Absolute URLs (Uniform Resource Locators) are full web addresses you see at the top of your browser when viewing a webpage. To use them, just put the URL in the href:
<a href="https://www.example.com/my-page">Visit my page</a>
Using Relative URLs

Relative URLs are links that point to a resource on the same domain as your current page. For instance, if your current page is 'https://www.example.com/my-other-page', using 'href="my-page"' will link to 'https://www.example.com/my-other-page/my-page'.
This is concise and more manageable when maintaining a website with many pages.
Linking to Internal and External Pages

Hyperlinks on a web page can either point to another page on the same site (internal link) or another web page (external link).
Internal links are typically used for navigating through different parts of a website, like from a homepage to an 'About' or 'Contact' page. They're useful for both users and search engine crawlers.




















Internal Linking
Internal linking is done using relative URLs since both pages exist under the same domain. Simply use the file name or folder path in the 'href':
<a href="/about">About</a>
External Linking
For external links, absolute URLs are your go-to. You need to include the full address to guide users outside of your site:
<a href="https://www.example.com">Visit example</a>
Remember to stay clear of downloading information from external sources without proper sanitization to protect your site and users from malicious activity.
Defining the Target of a Link
By default, all hyperlinks open in the same window or browser tab. However, sometimes it's desirable for them to open in a new tab or window. This can be achieved by using the 'target' attribute.
New Tab or Window
To open a link in a new tab or window, apply the 'target' attribute with the value '_blank':
<a href="https://www.example.com" target="_blank">Open link in new tab</a>
Defining Named Targets
Named targets allow for creating multiple windows or tabs and naming them for later use. For example:
<a href="https://www.example.com/#target1">Visit target 1</a>
Then, in another place on the page, create a target:
<a id="target1"></a>
Now, when you click 'Visit target 1', it scrolls directly to 'target1'.
Mastery of adding hyperlinks in HTML code isn't complex once you've comprehended these methods. This skill will boost your web development endeavours considerably.