How to Add a Link in HTML (and Open It in a New Tab)

Quick answer

<a href="https://example.com">Visit Example</a> <!-- open in a new tab --> <a href="https://example.com" target="_blank" rel="noopener">Visit Example</a>

Step 1: Create a basic link

A link has two parts: the address it goes to and the text people click.

  1. Type <a href=""> and put the address between the quotes.
  2. After it, write the link text: the words people will see and click.
  3. Close it with </a>.

Links can sit inside a sentence, like this link to our tutorials, or stand on their own. Edit the example: change an address or a link text.

index.html
Preview

Step 2: Absolute vs relative addresses

The href can be a full address or a short path relative to the current page:

Link tohref
Another websitehttps://example.com/page/ (absolute: always include https://)
A page in the same folderabout.html
A page in a subfolderblog/first-post.html
A page one folder up../index.html
From the root of your site/contact/ (on a web server)
A section on the same page#faq

Use relative or root paths for your own pages, so links keep working if you move the site to another domain. Always write the https:// for other websites: href="example.com" without it is treated as a file in your own folder.

Step 3: Open a link in a new tab

Add target="_blank" to open the link in a new browser tab. Browsers now automatically protect against the page you open being able to control yours, but adding rel="noopener" is still a good habit, and some older browsers need it.

<a href="https://example.com" target="_blank" rel="noopener">Example (opens in a new tab)</a>

Use new tabs sparingly. Opening a new tab takes control away from the visitor (they can always choose it themselves with a middle-click or long-press), and it can confuse screen reader and mobile users. Good reasons: links that would interrupt a task, such as a help page linked from a half-filled form, or a PDF. When you do use it, say so in the link text or with an icon, for example “(opens in a new tab)”.

Step 4: Link to a section on the same page

To jump to a specific part of a page, such as a table of contents does:

  1. Give the target element an id: <h2 id="pricing">Pricing</h2>.
  2. Link to it with a # and the id: <a href="#pricing">See pricing</a>.
  3. To link to a section on another page, add the id after its address: href="/plans/#pricing".

Add html { scroll-behavior: smooth; } in CSS for a smooth scrolling animation instead of a jump.

index.html
Preview

Step 5: Email, phone and download links

  • Email: <a href="mailto:hello@example.com">Email us</a> opens the visitor’s email app with a new message. Add a subject with ?subject=Hello.
  • Phone: <a href="tel:+15551234567">Call us</a> starts a call on phones. Write the number in international format, without spaces.
  • Download: add the download attribute to make the browser save the file instead of opening it: <a href="guide.pdf" download>Download the guide</a>. It only works for files on your own site.

Email addresses in links can be collected by spam bots. A contact form (see how to make a contact form that sends emails) avoids publishing the address at all.

Step 6: Make an image or button-style link

Anything inline can go inside <a>. Put an <img> inside it for a clickable image (its alt text becomes the link text, so describe the destination). Give the link a class and some padding to make it look like a button. It’s still a link, which is right for anything that goes to another page.

index.html
Preview

Style links with CSS

Links have four states you can style, and the order of the rules matters (remember “LoVe HAte”): a:link (not yet visited), a:visited, a:hover (mouse over it) and a:active (being clicked). Add a:focus-visible for keyboard users. Keep links recognisable: a different color and an underline (or another visual cue besides color) inside paragraphs, because some people can’t tell colors apart.

index.html
Preview

Make links accessible

  • Write link text that makes sense on its own. Screen readers can list every link on a page, so “Read more” five times tells nobody anything. “Read more about pricing” does.
  • Keep the focus outline. Keyboard users press Tab to move from link to link and rely on the outline to see where they are. Restyle it with :focus-visible instead of removing it.
  • Add a “skip to content” link as the very first link on the page (<a href="#main" class="skip-link">Skip to content</a>), visually hidden until focused. Keyboard users can then jump past the menu on every page.
  • Warn about surprises. Say when a link opens a new tab or downloads a file, for example “Annual report (PDF, 2 MB)”.

Useful <a> attributes

AttributeWhat it does
hrefThe destination (required for a real link)
target="_blank"Opens in a new tab or window
rel="noopener"Stops the new page from controlling yours
rel="nofollow" / "sponsored"Tells search engines not to pass ranking credit (use sponsored for paid or affiliate links)
downloadDownloads the file instead of opening it
titleTooltip text; don’t rely on it for important information

Common link mistakes

  • “Click here” as link text. Screen reader users often browse a list of links, and search engines use link text too. Describe the destination: “read the pricing guide”.
  • Forgetting https://. href="google.com" looks for a file named google.com on your own site.
  • Links that look like normal text. Give links a distinct color and an underline or other cue.
  • Opening every link in a new tab. Let visitors decide; use target="_blank" only when there’s a good reason, and say so.
  • Using a link as a button. <a href="#"> that only runs JavaScript should be a <button>.
  • Broken links. Check your links after moving or renaming pages; a 404 page frustrates visitors and wastes search engine visits.

Frequently asked questions

How do I add a link in HTML?
Use the <a> tag with an href attribute: <a href="https://example.com">Example</a>. The href is the address, and the text between the tags is what visitors click.
How do I make a link open in a new tab?
Add target="_blank" to the link, plus rel="noopener" for safety: <a href="https://example.com" target="_blank" rel="noopener">Example</a>. Use it sparingly and mention that the link opens a new tab.
How do I link to a section of the same page?
Give the target element an id, such as <h2 id="faq">, and link to it with a hash: <a href="#faq">FAQ</a>. To link to that section from another page, use the page address followed by #faq.
How do I make an email link in HTML?
Use mailto: in the href: <a href="mailto:hello@example.com">Email us</a>. Clicking it opens the visitor's email app with a new message to that address.
How do I remove the underline from a link?
Set text-decoration: none on the link in CSS. Inside paragraphs, keep another visual cue such as a different color, a bold weight or a bottom border, so visitors can still spot the link.
What is the difference between an absolute and a relative link?
An absolute link contains the full address including https:// and the domain. A relative link is a path from the current page, such as about.html or ../index.html, and keeps working if the site moves to another domain.