Loading

The HTML <a> tag is used to define hyperlinks. It allows users to click on text or elements and navigate to another document, file, section, email or URL.


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

Key Attribute: href
The href (Hypertext Reference) attribute defines the destination URL of the link. This can.
  • Absolute URL: https://example.com
  • Relative URL:  /contact.html
Absolute URL 
An Absolute URL is a complete web address that includes everything needed to find the page including the protocol (http or https), the domain name, and sometimes even a file path.

Example:
<a href="https://example.com">Visit Example</a>
In this case, the link will take your directly to the full website https://example.com, no matter where your current page is hosted.

Relative URL
A Relative URL is a shorter path that only works correctly when linked from within the same website or directory. it does not include the domain name or protocol.

Example:
<a href="/contact.html">contact us</a>
This link assumes you are already on the same website (like https://quipoin.com), and just points to a file or page inside that site in this case, /contact.html.


Common Attributes Used with <a> Tag

1. download
This attribute prompts the browser to download the linked resource instead of navigating.

Example:
<a href="logo.png" download>
 <img src="logo.png" alt="Quipoin" width="104" height="142">
</a>

Output:
Uploaded Image

Clicking the image will download the logo.png file.

2. target
It defines where to open the linked document.

common values:
ValueDescription
_blankOpens the link in a new tab or window
_selfOpens in the same frame (default behavior)
_parentOpens in the parent frame
_topOpens in the full body of the window
_framenameOpens in a named iframe, if specified

Example:
<a href="https://quipoin.com" target="_blank">Visit Quipoin</a>

Output:
Uploaded Image

Opens Quipoin in a new tab.


3. Linking an Email Address
Use mailto:  to allow users to send an email directly.

Example:
<a href="mailto:author@example.com">Send Mail</a>

Output:
Uploaded Image


4. Linking a Phone Number
Use tel: for clickable phone numbers on mobile devices.

Example:
<a href="tel:+911234567890">+91 1234567890</a>

Output:
Uploaded Image


5. Linking to a Section on the Same Page
Use an id in the target element and #id in the href.

Example:
<a href="#section2">Go to Section 2</a>

. . .

<h3 id="section2">This is Section 2</h3>

Output:
Uploaded Image

clicking on Go to Section you will go on the This is section 2

6. Triggering JavaScript with an Anchor
You can run JavaScript functions with the href="javascript:" approach.

Example:
<a href="javascript:alert('Hello Quipoin!');">Execute JavaScript</a>

Output:
Uploaded Image

while clicking on 'Execute JavaScript' you get alert.

Key Point
  • The <a> tag turns text or elements into hyperlinks.
  • href is mandatory for defining the link.
  • target="_blank" is commonly used to open links in a new tab.
  • download, mailto:, tel: and in-page links enhance usability.
  • JavaScript can also be linked using javascript: in the href.