HTML / HTML Links and Navigation
Creating Internal and External Links
In this tutorial, you'll learn how to create internal and external links using the <a> tag. Internal links lead to content within your own site, while external links lead to other…
Section overview
5 resourcesTeaches how to create hyperlinks and navigation menus in HTML.
1. Introduction
- Goal of the Tutorial: In this tutorial, we aim to help you understand how to create internal and external links in HTML using the tag.
- Learning Outcome: By the end of this tutorial, you'll be able to add internal links, which lead to different sections of your website, and external links, which lead to other websites.
- Prerequisites: Basic knowledge of HTML is required to follow this tutorial.
2. Step-by-Step Guide
- Internal Links: Internal links are used to navigate different sections within a webpage. These are created using the tag with the
hrefattribute pointing to an id on the page. - External Links: External links are used to navigate to different websites. These are also created using the tag with the
hrefattribute pointing to a URL.
Examples:
- Internal Link:
<a href="#section1">Go to Section 1</a> - External Link:
<a href="https://www.example.com">Visit Example.com</a>
Best practices and tips:
- Always use meaningful anchor text that gives a clear idea of what the link is about.
- For external links, it is generally a good practice to open the link in a new tab. This can be done by adding the
target="_blank"attribute to theatag.
3. Code Examples
Example 1: Internal Link
<!-- This is the link -->
<a href="#section1">Go to Section 1</a>
<!-- This is the destination -->
<div id="section1">
<h2>Section 1</h2>
<p>This is Section 1.</p>
</div>
- The
#section1in thehrefattribute is the destination of the link. - When you click on "Go to Section 1", the browser will scroll to the element with an id of "section1".
- The expected result is that the page will scroll to "Section 1".
Example 2: External Link
<a href="https://www.example.com" target="_blank">Visit Example.com</a>
- The
hrefattribute points to "https://www.example.com", which is the destination of the link. target="_blank"makes the link open in a new tab.- The expected result is that a new tab will open and load "example.com".
4. Summary
- You've learned how to create internal and external links using the tag.
- You've seen real-world examples of how these links are used.
- For further learning, you can explore other attributes of the tag.
5. Practice Exercises
Exercise 1: Create an internal link that navigates to a section at the bottom of the page.
Solution:
<a href="#bottom">Go to Bottom</a>
<div id="bottom">
<h2>Bottom of the Page</h2>
</div>
Exercise 2: Create an external link that opens in a new tab.
Solution:
<a href="https://www.google.com" target="_blank">Open Google</a>
Exercise 3: Create a navigation bar using internal links.
Solution:
<nav>
<a href="#home">Home</a> |
<a href="#about">About</a> |
<a href="#contact">Contact</a>
</nav>
<div id="home">
<h2>Home</h2>
</div>
<div id="about">
<h2>About</h2>
</div>
<div id="contact">
<h2>Contact</h2>
</div>
- This exercise combines multiple internal links to create a navigation bar.
- Each link leads to a different section on the page.
Need Help Implementing This?
We build custom systems, plugins, and scalable infrastructure.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Latest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI in Public Safety: Predictive Policing and Crime Prevention
In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…
Read articleAI in Mental Health: Assisting with Therapy and Diagnostics
In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…
Read articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article