D DevBrainBox

HTML5 Hyperlinks

HTML

A hyperlink (or simply "link") allows users to click and navigate from one page to another, to another location on the same page, or to resources like images, PDFs, downloads, etc.

Hyperlinks in HTML are created using the <a> (anchor) tag.

<a href="URL">Link Text</a>

<a>: The anchor element that creates the hyperlink.

href: The attribute that specifies the destination URL.

<a href="https://www.google.com">Visit Google</a>.

When clicked, it will take the user to www.google.com

1. Absolute URL

Links to an external website.

<a href="https://www.google.com" target="_blank" rel="noopener">Go to Google</a>

2. Relative URL

Links to another page within the same website.

<a href="about.html">About Us</a>

Using mailto: to open the default mail client.

<a href="mailto:info@example.com">Send Email</a>

Using tel: to start a call on mobile devices.

<a href="tel:+1234567890">Call Us</a>
<a href="#contact">Go to Contact Section</a>

<!-- later in the page -->
<h2 id="contact">Contact Us</h2>

Attributes of <a>

<a href="document.pdf" target="_blank" title="Download the document" download>
  Download PDF
</a>
AttributeDescription
hrefURL to navigate to
targetDefines where to open the link (_blank for new tab, _self for same tab)
titleTooltip text when you hover over the link
downloadTells browser to download the linked file instead of navigating to it

On this page