HTML Links - Detailed Overview

Introduction to HTML Links

HTML links are created using the <a> (anchor) element. Links allow users to navigate from one page to another, or to different sections within the same page. They can also link to external resources, such as documents or files.

Basic Link Syntax

The basic syntax for creating a link is as follows:

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

Here, href is an attribute that specifies the URL of the page the link goes to, and Link Text is the clickable text that the user will see.

Example 1: Internal Link

An internal link points to a location within the same document. For example, linking to a specific section of the page:

<a href="#section1">Go to Section 1</a>

To create the target section:

<h2 id="section1">Section 1</h2>

The link and the target:

Go to Section 1

Section 1

You've reached Section 1!

Example 2: External Link

An external link points to a different webpage or website:

<a href="https://www.shariqsp.com">Visit ShariqSP.com</a>

Click the following link to visit ShariqSP.com:

Visit ShariqSP.com

Opening Links in a New Tab

To open a link in a new tab or window, use the target="_blank" attribute:

<a href="https://www.shariqsp.com" target="_blank">Visit ShariqSP.com</a>

Click the following link to open ShariqSP.com in a new tab:

Visit ShariqSP.com in a new tab

Mailto Links

You can create a link that opens the user's default email client to send an email:

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

Click the following link to send an email:

Send Email

Linking to Files

Links can also point to files such as PDFs or images:

<a href="document.pdf">Download PDF</a>

Click the following link to download the file:

Download PDF