DevAcademy
LearnHTMLHTML Links
BeginnerHTML

HTML Links

Learn how to create links between pages and websites using the anchor element, and understand relative vs absolute URLs.

Reading Time

14 min

Lesson

Lesson 9 of 27

The Anchor Element

Links are created with the <a> (anchor) element. The href attribute specifies the destination the link points to.

Absolute vs Relative URLs

An absolute URL includes the full address, including protocol and domain (https://example.com/about). A relative URL points to a location relative to the current page (about.html or /about).

Opening in a New Tab Safely

<a href="https://example.com" target="_blank" rel="noopener noreferrer">
  Open in a new tab
</a>
Output

Linking to a Section on the Same Page

You can link to a specific element on the page using a fragment identifier — a hash (#) followed by the target element’s id.

Same-Page Anchors

<a href="#contact">Jump to Contact</a>

<!-- Later in the page -->
<h2 id="contact">Contact Us</h2>
Output

Other Common href Values

  • mailto:someone@example.com — opens the default email client
  • tel:+15551234567 — starts a phone call on mobile devices
  • # — links to the top of the current page

Best Practice

Always add rel="noopener noreferrer" when using target="_blank", and write descriptive link text for accessibility and SEO.

Interview Questions

Quick Quiz

1. Which attribute specifies the destination of a link?

2. What does target="_blank" do?

3. Which href value opens the user’s default email client?