HTML, CSS and JavaScript basics tutorial

Internal Links in HTML – Creating Efficient Connections

All videos of the tutorial HTML, CSS and JavaScript basics tutorial

You are at the beginning of your journey into the world of HTML, CSS, and JavaScript and wondering how to use internal links effectively? Internal links are a fundamental part of websites as they simplify navigation and improve the user experience. In this guide, I will explain the basics of internal linking within HTML documents.

Main insights

Step-by-step guide

Understanding internal links

Hyperlinks are the backbone of the internet. They allow navigation from one document to another. Imagine you have a recipe that mentions different ingredients. Instead of explaining everything in the same document, you can use links to separate explanations. This keeps the text clear, and the reader can easily retrieve additional information when needed.

Internal Links in HTML – Creating Efficient Connections

Creating a simple HTML page with links

To create interactive links, you need at least two HTML documents. I have prepared two files named page1.html and page2.html. Both files contain simple texts that act as mutual links. Open your development environment and create these two documents.

Setting up the anchor elements

To create a link, you use the tag, also known as the anchor tag. This tag is used to initiate the link and contains the link text that is visible to users.

In page1.html it would look like this: "Here is a link to go to page 2."

Checking the links

After creating, you should test the links to ensure they work. Load page1.html in the browser and click on the link to page2.html. If everything is correct, you will be redirected to the second page.

Internal Links in HTML – Creating Efficient Connections

Comparing relative and absolute links

Relative links refer to the current position in the directory and do not use a domain. For example: href="page2.html" is a relative link. Absolute links, on the other hand, always contain the full URL, e.g., href="http://example.com/page2.html". This can be useful in various contexts, such as linking to external websites.

Using directories for structure

When you create directories for your pages, the structure of your links can become more complicated. Let's say you have a subdirectory called subdirectory which contains page3.html.

Make sure the linking is correct and test it in the browser.

The use of dot-dot notation

If you are in a subdirectory and need to return to a parent level, you can use dot-dot notation (..). This directs the browser one level up in the directory tree.

This link will take you back to the first page, even if you are in the subdirectory.

Conclusion on the importance of internal links

Understanding how internal links work is crucial for a coherent and user-friendly website. Using anchor elements and the correct linking structure makes navigation significantly easier for your users. Whether relative or absolute – you now have the basics to implement internal links effectively.

Summary – Internal Links in HTML: Basics for Linking

Internal links are essential for navigation within your web pages. You have learned how to create links with the anchor tag, distinguish between relative and absolute links, and how to optimally utilize the structure of your links. Use this knowledge to create clear and user-friendly navigation structures.

Frequently Asked Questions

How do I create an internal link in HTML?Use the tag with the href attribute to link to another HTML page.

What is the difference between relative and absolute links?Relative links refer to the current page, while absolute links contain the full URL.

How do I test if my links work?Load the HTML page in the browser and click on the link; if you are redirected to the correct page, it works.

What do I do if I have a broken link?Check the file path and ensure the linked file exists in the specified directory.

How do I use dot-dot notation in links?With ".." you can navigate one level up in the directory tree in the link.

274