Links

BrandonDusch's avatar
Published Aug 3, 2021Updated Apr 24, 2025
Contribute to Docs

In HTML, links (also called hyperlinks) allow users to navigate between different web pages or external resources. They are created using the <a> (anchor) tag, which can point to another webpage, file, or location within the current document.

Syntax

<a href="url">Link Text</a>
  • href: Specifies the destination URL.
  • Link Text: The clickable text shown to users.

By default, links will appear as follows in most browsers:

  • Unvisited links are underlined and blue
  • Visited links are underlined and purple
  • Active links (during click) are underlined and red

Example

Text wrapped in a linked anchor tag becomes a hyperlink to another page:

<!-- Creating a link -->
<a href="https://www.codecademy.com/learn">My Home</a>

The output of the example code will look like this:

Showcasing the use of html links

Points to a page within the same website.

<!-- Creating a text link -->
<a href="#data-science-jobs">Data science jobs</a>

The output of the example code will look like this:

Showcasing the usage of internal links in html

Points to a web page on a different domain.

<a href="https://example.com">External Site</a>

Anything that is inside the anchor tag will be treated as a link. In this case, the Codecademy logo will take the user to the Codecademy home page.

<!-- Creating an image link -->
<a href="http://www.codecademy.com">
<img src="logo.jpg" alt="Codecademy Logo" />
</a>

The result of the example code will appear as:

Showcasing the use of image as a link in html

Special strings can be passed to the href attribute to link email accounts ("mailto:[email protected]") or phone numbers ("tel:###-###-####"):

<!-- This link will try to create a new email to [email protected]. -->
<!-- This link will try to call phone number 234-555-1212. -->
<a href="tel:234-555-1212">234-555-1212</a>

The actions defined by these links will be completed depending on the user’s device and settings. For example, clicking a phone link while on a cell phone may use the built in dialer to complete the call.

Frequently Asked Questions

1. What does the target="_blank" attribute do?

It opens the link in a new browser tab or window.

Yes. The href attribute can link to any resource, including documents or images.

<a href="files/resume.pdf">Download Resume</a>

Use href="#section-id" where the section has a corresponding id attribute.

All contributors

Contribute to Docs

Learn HTML on Codecademy