HTML Tutorial

HTML Tag: <a>

Usage:

The <a> tag, short for "anchor," is used to create hyperlinks in HTML documents. It allows you to link to web pages, files, sections within a page, or other resources.

Attributes:

  • href: Specifies the destination URL of the link.
  • title: Provides a tooltip text that appears when users hover over the link.
  • target: Controls where the linked page opens.
  • _blank: Opens the link in a new tab or window.
  • _self: Opens the link in the same tab or window.
  • rel: Specifies the relationship between the current page and the linked page. Common values include:
  • noopener: Prevents the linked page from accessing the current page's window or frames.
  • noreferrer: Prevents the linked page from knowing where the link was clicked from.

Examples:

  • Link to a web page: <a href="www.google.com">Google</a>
  • Link to a file: <a href="myfile.pdf">Download File</a>
  • Link to an email address: <a href="mailto:[email protected]">Email John</a>
  • Link to a section within the same page: <a href="#section-name">Jump to Section</a>

Accessibility:

For accessibility, it's important to:

  • Provide descriptive link text that clearly indicates the destination.
  • Avoid using the same link text for different links.
  • Use the title attribute to provide additional information about the link.

HTML Example: Exploring the <a> Tag

<!DOCTYPE html>
<html>
<body>
  <h1>My Website</h1>

  <p>
    Here is a link to <a href="www.google.com">Google</a>.
  </p>

  <p>
    Want to know more about me? <a href="#about-me">Click here to read my bio</a>.
  </p>
</body>
</html>