HTML Links

Beginner
10 min read
Updated: Nov 2026
6 examples
<a href>

Definition and Usage

An HTML link (hyperlink) connects the current page to another resource. You create one with the <a> element. The href attribute holds the destination; the content inside <a>—text, an image, or other phrasing content—is what visitors click.

What can a link point to?

Another HTML page, a PDF or download, an email address (mailto:), a phone number (tel:), or a section on the same page via a fragment (#id). Absolute URLs name a full address; relative URLs navigate within your own site.

Why links matter

Links are the spine of the web. Clear link text, correct paths, and thoughtful target / rel choices make navigation predictable for everyone—including keyboard and screen-reader users.

When should you use them?

Anytime someone needs to leave the current view for related content, contact you, jump to a heading, or open a resource in a new tab. Prefer descriptive labels over “click here.”

The <a> element.

Without a valid href, an <a> is not a hyperlink—it is just a placeholder. Always set href for real navigation.

New tabs need rel.

When you use target="_blank", add rel="noopener noreferrer" so the new page cannot access window.opener.

Link text should describe the destination.

Screen readers often list links out of context. Phrases like “HTML Lists tutorial” beat “read more.”

HTML Link Syntax

The basic form:

link.html
<a href="url" >Link text</a>
HTML
<!-- Absolute URL -->
<a href="https://www.example.com">Example site</a>

<!-- Relative URL -->
<a href="about.html">About us</a>

<!-- Open in a new tab -->
<a href="https://www.example.com" target="_blank" rel="noopener noreferrer">Example (new tab)</a>

<!-- Fragment / bookmark -->
<a href="#faq">Jump to FAQ</a>

<!-- Email -->
<a href="mailto:[email protected]">Email us</a>

<!-- Tooltip -->
<a href="guide.html" title="Open the beginner guide">Guide</a>

Common attributes: href (required for a real link), target (_self, _blank, and others), rel, title, and download for file saves.

Core HTML Concepts

Ideas that keep hyperlinks correct and usable:

ConceptMeaning
<a href="…">Creates a hyperlink to the given URL
Absolute URLFull address with scheme and host (https://…)
Relative URLPath resolved from the current page (page.html, ../docs/)
target="_blank"Opens the destination in a new tab or window
target="_self"Default—navigates in the same browsing context
Fragment (#id)Scrolls to an element with a matching id on the page
mailto:Opens the user’s email client with a prefilled address
titleAdvisory tooltip text on hover (not a substitute for visible labels)

Absolute vs relative

AbsoluteRelative
Examplehttps://codetofun.com/htmllists.html or /html/lists
Best forExternal sitesPages inside your project
Breaks if site moves?Only if the remote host changesCan break if folder structure changes

How to Use Links in HTML

Practical habits for clear, safe navigation.

  1. Write <a href="…">descriptive text</a> where navigation belongs.
  2. Prefer relative paths for your own pages; use absolute URLs for other sites.
  3. Add target="_blank" only when a new tab helps—and always include rel="noopener noreferrer".
  4. For same-page jumps, set an id on the target and link with href="#id".
  5. Use mailto: for contact links; wrap images in <a> when the graphic is the control.
  6. Keep title optional and short—visible text remains primary.
GoalPattern
Internal page<a href="about.html">About</a>
External site<a href="https://…" target="_blank" rel="noopener noreferrer">…</a>
Same-page section<a href="#pricing">Pricing</a>
Email<a href="mailto:[email protected]">Email</a>
Image link<a href="…"><img src="…" alt="…"></a>

Live Preview

Switch link styles and inspect the rendered markup shape. Click Apply after you pick a mode.

Shows how different link patterns look and how their source is shaped.

Rendered page

Visit the Example site for demos.

<a href="https://www.example.com">Example site</a>

HTML Examples

Six patterns: basic href, target blank/self, absolute vs relative, image as link, mailto + title, and bookmark fragments.

Example 1 — Basic Link with href

HTML
<p>
  Learn more on the
  <a href="https://www.example.com">Example website</a>.
</p>
Try It Yourself

How It Works

  1. <a href> marks the clickable phrase.
  2. Link text names the destination clearly.
  3. Default target is _self—same tab.
  4. Use for everyday navigation between pages.

Example 2 — target="_blank" and "_self"

HTML
<p>
  Same tab:
  <a href="https://www.example.com" target="_self">Example (self)</a>
</p>
<p>
  New tab:
  <a href="https://www.example.com" target="_blank" rel="noopener noreferrer">Example (blank)</a>
</p>
Try It Yourself

How It Works

  1. _self replaces the current page (browser default).
  2. _blank opens a separate tab or window.
  3. rel="noopener noreferrer" hardens new-tab links.
  4. Reserve _blank for external or parallel reading, not every internal click.

Example 3 — Absolute vs Relative URLs

HTML
<ul>
  <li><a href="https://www.example.com/docs">Absolute docs URL</a></li>
  <li><a href="about.html">Relative: about.html</a></li>
  <li><a href="../index.html">Relative: parent folder</a></li>
  <li><a href="/html/lists">Root-relative path</a></li>
</ul>
Try It Yourself

How It Works

  1. Absolute URLs include protocol and host.
  2. Same-folder relatives use just the file name.
  3. ../ climbs one directory level.
  4. Leading / resolves from the site root.

Example 4 — Image as a Link

HTML
<a href="https://www.example.com">
  <img src="https://placehold.co/200x120/2563eb/white?text=Logo"
       alt="Example company home page"
       width="200" height="120">
</a>
Try It Yourself

How It Works

  1. Wrap img inside <a> to make the graphic clickable.
  2. alt text should describe where the link goes when the image is the only content.
  3. Width/height reduce layout shift while the image loads.
  4. See also the HTML Images tutorial.

Example 5 — mailto and title Tooltip

HTML
<p>
  Questions?
  <a href="mailto:[email protected]?subject=Hello%20from%20the%20site"
     title="Opens your email app">Email the team</a>.
</p>
Try It Yourself

How It Works

  1. mailto: hands off to the user’s mail client.
  2. Query params like subject= can prefill the message.
  3. title shows a small tooltip on hover—extra hint, not the main label.
  4. Visible text still carries the meaning for accessibility.

Example 6 — Bookmark / Fragment Links

HTML
<nav>
  <a href="#intro">Intro</a> |
  <a href="#details">Details</a>
</nav>

<h2 id="intro">Introduction</h2>
<p>Welcome to the links tutorial overview.</p>

<h2 id="details">Details</h2>
<p>Fragment links scroll to matching id values.</p>

<p><a href="#top">Back to top</a></p>
Try It Yourself

How It Works

  1. id on headings creates named destinations.
  2. href="#id" scrolls to that element.
  3. In-page nav suits long articles and FAQs.
  4. IDs must be unique within the document.

Edge Cases & Pitfalls

Broken or unsafe links often come from empty hrefs, missing rel, or vague labels.

href

Empty or missing href

href="" or no href does not create a reliable hyperlink. Use a real URL or omit the link until the destination exists.

blank

target="_blank" without rel

New pages can reverse-tabnab the opener. Always add rel="noopener noreferrer".

label

“Click here” link text

Vague labels fail when links are listed alone. Name the page or action instead.

fragment

Fragment with no matching id

href="#missing" does nothing useful if no element has that id. Keep ids and links in sync.

nest

Interactive content inside <a>

Do not nest buttons or other links inside an anchor. Keep link content phrasing-level (text, images, spans).

title

Relying only on title

Tooltips are inconsistent on touch devices and for assistive tech. Visible link text must stand alone.

Browser Support

The HTML a element and hyperlink attributes are part of the HTML language and work in all browsers.

✓ Baseline · Widely available

HTML links

Every modern browser supports href, target, mailto, and fragment navigation on the a element.

100% a / href support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support

Key Takeaways

  • <a href="…"> creates a hyperlink; descriptive text (or alt on image links) names the destination.
  • Absolute vs relative URLs: full host for externals, paths for your own site.
  • target="_blank" needs rel="noopener noreferrer"; default is _self.
  • Fragments, mailto, and image links extend the same <a> pattern.

One line: Write <a href="destination">clear label</a>, choose absolute or relative URLs wisely, and harden new tabs with rel.

Frequently Asked Questions

An HTML link (hyperlink) is created with the a element. Its href attribute names the destination—another page, a file, an email address, or a section on the same page. Visitors click the link text or nested content to navigate.
Write <a href="url">link text</a>. Replace url with an absolute address (https://…), a relative path (about.html), a fragment (#section), or a mailto: address.
An absolute URL includes the scheme and host (https://example.com/page). A relative URL is resolved against the current page’s location (page.html or ../docs/guide.html). Use relative paths for links inside your own site.
Use target="_blank" to open the destination in a new browsing context (usually a new tab). Pair it with rel="noopener noreferrer" for security and privacy. Prefer _self (the default) when the user should stay in the same tab.
Give the target element an id, then set href="#that-id". Clicking the link scrolls to that element. These are called bookmark or fragment links.
Yes. Wrap an img element inside an a element. The image becomes the clickable surface. Always keep a meaningful alt on the image so assistive tech can describe the link destination.

Practice in the editor

Open a Try It demo and edit href, target, mailto, and fragment links live.

Open Try It editor →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful