Links in HTML

Capítulo 7

Estimated reading time: 3 minutes

+ Exercise
Audio Icon

Listen in audio

0:00 / 0:00

Links in HTML

Links are one of the most important elements in HTML as they allow users to navigate between different web pages. In HTML, links are created using the <a> tag, which stands for "anchor".

To create a link, you need to specify the URL of the page you want to link to. The URL is the string of characters that uniquely identifies a web page. For example, the Google home page URL is https://www.google.com.

To link to Google, you can use the following HTML code:

<a href="https://www.google.com">Google</a>

In this example, the text "Google" is the link text that will be displayed on the page. The href attribute specifies the URL the link points to.

In addition to the href attribute, you can also add other attributes to the <a> element. For example, the target attribute specifies where the linked page will open. If you set the attribute value to "_blank", the page will open in a new browser window. For example:

Continue in our app.
  • Listen to the audio with the screen off.
  • Earn a certificate upon completion.
  • Over 5000 courses for you to explore!
Or continue reading below...
Download App

Download the app

<a href="https://www.google.com" target="_blank">Google</a>

You can also add a title to the link using the title attribute. The title is displayed as a tooltip when the user hovers over the link. For example:

<a href="https://www.google.com" title="Go to Google">Google</a>

In addition, you can link to specific sections of a page using anchors. Anchors are bookmarks within a page that allow you to link directly to a specific section. To create an anchor, you need to add the id attribute to an element on the page. For example:

<h2 id="my-section">My section</h2>

To create a link to this section, you can use the following code:

<a href="#my-section">Go to my section</a>

In this example, the href attribute value starts with a hash sign (#), followed by the id attribute value of the element you want to link.

In summary, links are a fundamental part of HTML and allow users to easily navigate between different web pages. With the <a> tag, you can create links to other websites, specific sections of a page, and even open pages in a new browser window.

Now answer the exercise about the content:

_What is the role of the "target" attribute in the <a> tag in HTML?

You are right! Congratulations, now go to the next page

You missed! Try again.

The target attribute in the <a> tag specifies where the linked page will open. For example, setting it to _blank opens the link in a new browser window.

Next chapter

Tables in HTML

Arrow Right Icon
Free Ebook cover Complete HTML Course
19%

Complete HTML Course

4.38

(8)

37 pages

Download the app to earn free Certification and listen to the courses in the background, even with the screen off.