HTML

How to Create Links in HTML with the Anchor Tag

How to create links in HTML with the <a> tag: internal and external links, email links, and the attributes that control how they open.

RazakTerra
Reading time
2 min read
Comments
Discussion
How to Create Links in HTML with the Anchor Tag
On this page
  1. Basic Link Syntax
  2. External Links
  3. Internal Links
  4. Anchor Links (Jump to a Section)
  5. Email Links
  6. Useful Attributes
  7. Target Controls where the link opens:
  8. rel
  9. Full Example
  10. Quick Tips
HTML
<a href="https://example.com">Visit Example</a>
  • href → the destination of the link (required)
  • The text between the opening and closing tags is what users see and click

These point to another website.

Playground
<a href="https://packcamo.com/">Go to Pack Camo</a>
<a href="https://packcamo.com/" target="_blank">Open Pack Camo in new tab</a>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

These link to another page on the same website.

Playground
<a href="/about">About Me</a> <a href="/blog">All Article</a>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

You can link to a specific part of the same page using an id.

Playground
<!-- The link that jumps to it -->
<a href="#first-section">Go to first section</a>
<a href="#second-section">Go to second section</a>

<!-- The target section -->
<h2 style="height: 100vh" id="first-section">First Section</h2>
<h2 style="height: 100vh" id="second-section">Second Section</h2>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

You can also link to a section on another page:

Playground
<a href="/#apps">Other Apps</a>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

Use mailto: to open the user’s email app.

Playground
<a href="mailto:hello@coresintext@gmail.com">Send me an email</a>
<a href="mailto:hello@coresintext@gmail.com?subject=Hello"
  >Email with subject</a
>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

Useful Attributes

Playground
<a href="https://example.com" target="_blank">Open in new tab</a>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

rel

Adds extra information about the link relationship. Commonly used with target=“_blank” for security:

Playground
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
  External Link
</a>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

Full Example

Playground
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Links Example</title>
  </head>
  <body>
    <h1>My Website</h1>

    <p>
      Visit
      <a href="https://google.com" target="_blank" rel="noopener noreferrer"
        >Google</a
      >
      or read our <a href="about.html">About page</a>.
    </p>

    <p>
      <a href="#services">Jump to Services</a>
    </p>

    <h2 id="services">Our Services</h2>
    <p>We offer web design and development.</p>

    <p>Questions? <a href="mailto:hello@example.com">Email us</a>.</p>
  </body>
</html>
Result
Cmd/Ctrl + Enter runs it · Esc leaves the editor

Quick Tips

Always use clear and descriptive link text (avoid “click here”). Add rel="noopener noreferrer" when using target="_blank" for better security. Use anchor links (#id) to help users jump to important sections. Test your links to make sure they go to the right place.

With just the <a> tag and a few attributes, you can create almost any kind of link your website needs.

Written by

Razak

Writes about the web, slowly, and builds small tools on the side.

Discussion

Comments

Loading comments…

Keep reading