HTML Links

Links are used in HTML to navigate from one page to another. They are created using the <a> (anchor) tag.

Basic Syntax

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

This will display as a clickable link: Visit google

Target Attribute

You can use the target attribute to control how the link opens:

<a href="https://www.example.com" target="_blank">Open in new tab</a>

This opens the link in a new tab or window.

Linking to a Page in Your Website

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

This links to a file named about.html in the same folder.

Linking to an Email Address

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

Linking to a Phone Number

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

Using Links to Jump Within a Page

You can create a link to a specific section in the same page using an ID:

<a href="#contact">Go to Contact</a>
...
<h2 id="contact">Contact Section</h2>

Best Practices

  • Use descriptive text in links (avoid "click here").
  • Always include the href attribute.
  • Use target="_blank" responsibly to avoid confusing users.