Links

`<a href>` — the Element That Made the Web

Links

Links are the original web feature. Master `href`, `target`, `rel`, and the difference between absolute and relative URLs.

4 min read Level 1/5 #html#links#a
What you'll learn
  • Link to internal and external pages
  • Open links in a new tab safely
  • Use anchor links to scroll within a page

<a href="..."> is the anchor element — the original web feature. Clicking it navigates.

Basic Form

<a href="/about">About us</a>
<a href="https://example.com">Example</a>
<a href="mailto:hi@example.com">Email us</a>
<a href="tel:+15551234">Call us</a>

Absolute vs Relative URLs

URLWhat it means
https://example.com/aboutAbsolute — full URL
/aboutRoot-relative — relative to the site root
about.htmlRelative — same folder as the current page
../about.htmlOne folder up
#section-2Anchor on the current page
/about#contactAnchor on another page

For internal links within your site, root-relative (/about) is usually safest — it works regardless of which page the user is on.

<h2 id="install">Installation</h2>
<!-- ... -->
<a href="#install">Jump to installation</a>

Clicking the link scrolls the matching id into view.

Opening in a New Tab

<a href="https://example.com" target="_blank" rel="noopener noreferrer">
  Example (new tab)
</a>
  • target="_blank" — opens in a new tab
  • rel="noopener" — security: prevents the new page from accessing window.opener
  • rel="noreferrer" — extra privacy

For external links, both noopener and noreferrer are the safe default.

rel Values Worth Knowing

rel valueMeaning
noopenerPrevent window.opener access from new tab
noreferrerDon’t send the Referer header
nofollowTell search engines not to follow / weight this link
externalThis goes off-site
authorLink to the page’s author
next / prevPagination relationship

Wrapping More Than Text

You can wrap any inline content — and many block elements — in an <a>:

<a href="/article">
  <article>
    <h2>Article Title</h2>
    <p>Lead paragraph...</p>
  </article>
</a>

Block-level linking is fine in HTML5. The whole region becomes clickable.

If clicking it navigates → <a href>. If clicking it does something (submit, toggle, open a modal) → <button>. Style them however you like — but use the right element.

Up Next

Images.

Images →