HTML Links

Links connect pages and are created with the <a> element and its href attribute.

Links are what make the web a web. The text between the tags is what the user clicks, and href says where that click leads.

Creating a Link

A basic link

<!DOCTYPE html>
<html>
<body>

<a href="https://www.hyring.com">Visit Hyring</a>

</body>
</html>

Kinds of Link

  • An absolute link points to a full address, like https://www.hyring.com.
  • A relative link points to another file in your own site, like about.html.
  • A link to an id jumps to a spot on the same page, like #pricing.

Opening in a New Tab

The target attribute

<!DOCTYPE html>
<html>
<body>

<a href="https://www.hyring.com" target="_blank">Open in a new tab</a>

</body>
</html>
Note: Use relative links inside your own site so they keep working if the site moves to a new domain.

Exercise: HTML Links

Which attribute specifies the destination URL of a link?