<a>
The anchor tag

The HTML <a> tag, also known as the anchor tag, is used to create hyperlinks, allowing users to navigate between different web pages, sections of a page, or external websites. It is one of the most fundamental elements in web development.

basic syntax

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

The href attribute defines the destination URL where the link should point. The link text (between the opening and closing <a> tag) is what users will click on.

Linking to an External Website

To create a link to an external site, provide the full URL in the href attribute:

<a href="https://www.example.com">Visit Example</a>

To open the link in a new tab, add the target="_blank" attribute:

<a href="https://www.example.com" target="_blank">Visit Example</a>

Linking to Another Page on the Same Website

You can link to another page within your website by specifying the relative path:

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

If the page is in a different folder, specify the path:

<a href="pages/contact.html">Contact</a>

Linking to a Section Within a Page

To navigate to a specific section on the same page, use an id in the target element and link to it using #id:

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

Section 2

Email and Phone Links

The <a> tag can also be used to create email and phone links:

Email: Opens the default email client with a pre-filled email address:

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

Phone: Initiates a phone call on mobile devices:

<a href="tel:+1234567890">Call Us</a>

Adding a Downloadable File Link

If you want users to download a file, use the download attribute:

<a href="files/sample.pdf" download>Download PDF</a>