SyntaxStudy
Sign Up
HTML Beginner 5 min read

Anchor Tag Basics

Anchor Tag Basics

The <a> (anchor) element creates a hyperlink. The most important attribute is href (Hypertext REFerence), which specifies the URL the link points to. The clickable content goes between the opening and closing tags.

Absolute vs Relative URLs

An absolute URL includes the full address starting with https://. Use these for external websites. A relative URL omits the domain and is resolved relative to the current page — use these for internal pages within the same site. Relative URLs make your site portable across different domains and environments.

  • href="https://example.com" — Absolute (external)
  • href="/about.html" — Root-relative (internal)
  • href="about.html" — Relative to current folder
Example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Links</title>
</head>
<body>
  <h1>HTML Links</h1>

  <!-- Absolute URL -->
  <p><a href="https://www.w3schools.com">Visit W3Schools</a></p>

  <!-- Root-relative -->
  <p><a href="/about.html">About Us</a></p>

  <!-- Relative -->
  <p><a href="contact.html">Contact</a></p>

  <!-- Link with title tooltip -->
  <p>
    <a href="https://developer.mozilla.org"
       title="MDN Web Docs">
      MDN Reference
    </a>
  </p>
</body>
</html>
Pro Tip

Always write descriptive link text — avoid generic phrases like "click here" or "read more". Screen readers list all links on a page, so meaningful text like "Download the PDF guide" helps users navigate without reading surrounding content.