30 Mins

4. Links & Navigation

Anchor Tags

The <a> (anchor) tag is the cornerstone of the web, allowing users to navigate between documents or sections within a document. Its primary attribute, href, specifies the destination URL, effectively transforming text or elements into interactive hyperlinks.

Always provide descriptive link text for screen readers instead of "click here". This improves accessibility and provides context for users navigating via assistive technology.

Operator Note: Use the aria-label attribute if the link text alone is not descriptive enough to explain the destination's purpose.
HTML
<a href="https://learn.voidxhq.com"> Visit VoidX Academy </a>

Relative vs Absolute Links

Absolute links use the full URL including the protocol (http/https), pointing to a fixed external location. Relative links point to resources based on the current page's file location, making them ideal for internal site navigation.

Relative links are more portable. When you move files within your directory structure, relative links remain functional, whereas absolute links to your own site may break or force unnecessary browser reloads.

Operator Note: Default to relative links for all internal site navigation to maintain site performance and portability.
HTML
<!-- Absolute -->
<a href="https://google.com"> Google </a>
<!-- Relative -->
<a href="/about-us"> About Us </a>

Email Links (mailto)

The mailto: scheme allows users to open their default email client pre-populated with a recipient's address. It is defined within the href attribute of an <a> tag.

You can extend functionality by adding parameters like subject or body to the link, streamlining communication for the user. Note that this requires users to have an email client configured on their device.

Operator Note: Test mailto links on mobile devices to ensure they trigger the correct native mail application.
HTML
<a href="mailto:recruit@voidxhqhqhq.com?subject=Inquiry"> Send Email </a>

Phone Links (tel)

The tel: scheme is used to create clickable telephone links. When triggered on mobile devices, it prompts the operating system to initiate a phone call to the specified number.

Ensure the number format is international-friendly, usually starting with a plus sign, to guarantee it works across different regional calling standards.

Operator Note: Only use tel links on mobile-responsive designs or pages likely to be viewed on phone-enabled devices.
HTML
<a href="tel:+15550199"> Call Support </a>

Download Links

The download attribute on an <a> tag instructs the browser to download the linked resource rather than navigating to it. This is useful for providing PDF manuals, images, or assets to users.

You can provide an optional value to the download attribute to suggest a specific filename for the saved file, which improves user experience and organization for the downloader.

Operator Note: Ensure your server provides the correct MIME type for the file, otherwise the download attribute may be ignored.
HTML
<a href="/files/manual.pdf" download="VoidX_Manual.pdf"> Download Manual </a>

Target Attribute

The target attribute specifies where to display the linked resource. Setting it to _blank instructs the browser to open the destination in a new tab or window.

When using target='_blank', always include rel='noopener' or rel='noreferrer' to prevent the new page from accessing the original window's window.opener object, which is a critical security vulnerability.

Operator Note: Opening links in new tabs can disrupt navigation for some users. Use it sparingly, mainly for external sites or tools.
HTML
<a href="https://external.com" target="_blank" rel="noopener">
  External Site
</a>

IDs and Page Section Navigation

By assigning a unique id to an HTML element, you can create a link that scrolls directly to that specific section within the same page using the hash (#) symbol in the href attribute.

This is essential for long-form documentation or single-page applications. It also allows for "Back to Top" functionality, which enhances usability for users scrolling through large amounts of content.

Operator Note: IDs must be unique within the entire document; you cannot use the same ID twice on a single page.
HTML
<a href="#section1"> Go to Section 1 </a>
<div id="section1">Content Area</div>

Knowledge Check

Ready to test your understanding of 4. Links & Navigation?

Back