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.
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.
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 1You've reached Section 1!
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.comTo 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 tabYou 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 EmailLinks 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