3.1. Creating Links (15 minutes)

  • Detailed review of the <a> tag for hyperlinks​.

  • Internal vs. external links.

  • Opening links in a new tab using target="_blank".

The <a> tag (anchor tag) is used to create hyperlinks in HTML, allowing users to navigate from one page to another. This tag is fundamental to how the web works, as it enables users to click on text or images and be directed to other resources, either within the same site or to an external website.

Here’s the basic syntax of the <a> tag:

// Some code
<a href="https://www.example.com">Link Text</a>
  • href (Hypertext REFerence): This attribute specifies the URL or file path of the page or resource the link points to. When users click the link text, they are directed to the specified URL

    • Example for an external link:

      <a href="https://www.wikipedia.org">Visit Wikipedia</a>
    • Example for an internal link (within the same site):

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

The clickable link text can be any text or even an image that a user clicks on to navigate.

Internal vs. External Links

  • Internal Links: These links point to other pages or resources within the same website. They often reference other HTML files within the same project folder or sections of the same page (also known as anchor links).

    • Example of an internal link to another page on the same site:

  • External Links: These links direct users to other websites outside the current domain. They usually start with a full URL (e.g., https://).

    • Example of an external link:

Using internal and external links helps users navigate effectively within your website or to external resources.

Opening Links in a New Tab Using target="_blank"

The target="_blank" attribute is used to open a link in a new browser tab or window. This can be especially useful for external links when you want the user to remain on your website while still visiting the linked resource.

Example of a link opening in a new tab:

  • target="_blank": This attribute tells the browser to open the link in a new tab or window, depending on the browser settings.

  • Example without target="_blank":

    • The link opens in the same tab, replacing the current page.

Activity for Students

Objective:

In this activity, students will practice creating links using the <a> tag, including both internal and external links. They will also learn how to open links in a new tab using the target="_blank" attribute.

Activity Steps:

  1. Open the Existing HTML File:

    • Instruct students to open their existing HTML file (e.g., exercise.html) using a text editor (such as Notepad or Visual Studio Code).

  2. Add Multiple Links:

    • Ask students to add several hyperlinks to their webpage, including both internal links (links to other pages within the same site) and external links (links to other websites).

    • Example code to add to their webpage:

  3. Create Internal Links:

    • If students don’t have an internal page (like about.html), they can create a simple placeholder page. Instruct them to create a new HTML file named about.html with the following content:

    • Save this file in the same folder as their main HTML file. Now, the internal link will work correctly.

  4. Save and Test the Links:

    • Students should save their updated HTML file and open it in their browser.

    • Test the following:

      • Internal links should navigate to the local about.html page.

      • External links should navigate to external websites like Wikipedia.

      • Links with target="_blank" should open in a new tab.

  5. Experiment with More Links (Optional):

    • Encourage students to add more links, including links that open in the same tab or new tab, and internal links that direct to different sections of the same page (using anchor links).

    • Example of an anchor link:

Practice Example

Discussion and Reflection:/

After the activity, ask students to reflect on the following questions:

  • What is the difference between internal and external links?

  • When might it be useful to open a link in a new tab using target="_blank"?

  • How does linking improve user navigation on a website?

Encourage students to share their experiences with creating links and discuss any challenges they faced during the activity.

Extended Activity (Optional):

For students who finish early or want more practice, suggest the following:

  1. Add Links to Different Sections of the Same Page (Anchor Links):

    • Students can add anchor links that navigate to different parts of the same page.

      • Example:

  2. Style Links with CSS (Optional):

    • Encourage students to experiment with CSS to style their links. For example, they can change the color or remove the underline from links:

By the end of this activity, students will have a clear understanding of how to create internal and external links, as well as how to control whether links open in the same tab or a new one. They will also be able to use these skills to enhance navigation and user experience on their webpages.

Last updated