HTML Course

Lesson 4: Links

Basic Links

Links are created with the <a> tag, using the href attribute to specify the destination.

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

Absolute vs Relative URLs

<a href="about.html">About Us</a>   <!-- relative link -->
<a href="https://www.google.com">Google</a>  <!-- absolute link -->

Opening in a New Tab

Use target="_blank" to open a link in a new browser tab. Always include rel="noopener noreferrer" for security.

<a href="https://www.wikipedia.org" target="_blank" rel="noopener noreferrer">Wikipedia</a>

Linking to a Section on the Same Page

You can link to an element’s id within the same page.

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

...

<h2 id="section2">This is Section 2</h2>

Exercise

Create a webpage with:

  1. A link to your school's homepage (absolute link).
  2. A link to another lesson in your HTML course (relative link).
  3. A link to a section further down the same page.
  4. A link that opens in a new tab.