HTML Β· Chapter 14 of 45

HTML Links

The <a> (anchor) tag creates a hyperlink, using the href attribute to specify the destination URL. Links can point to other pages, sections within a page, email addresses, or files.

The target attribute controls where the link opens β€” target="_blank" opens it in a new tab. Anchor links use an id and a hash (#) to jump to specific parts of a page.

Syntax
<a href="url">link text</a>

Basic and external links

<a href="page.html">Link</a> creates a clickable link. Use target="_blank" to open external links in a new tab, often combined with rel="noopener" for security.

Email and anchor links

mailto: links open the user's email client. Linking to href="#section-id" scrolls to an element with a matching id on the same page.

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

target="_blank" opens the link in a new browser tab.

Example 2 (html)
<a href="mailto:info@example.com">Email us</a>
<a href="#section2">Jump to Section 2</a>
Output
Email us / Jump to Section 2

mailto links open email apps; # links scroll to page anchors.

Key points

  • <a href="..."> creates a hyperlink.
  • target="_blank" opens links in a new tab.
  • mailto: links open the default email client.
  • href="#id" jumps to an element with a matching id.
πŸ’‘ Note: Always pair target="_blank" with rel="noopener" to prevent security vulnerabilities.

πŸ“ Quick Quiz

1. Which attribute defines a link's destination?

2. What does target="_blank" do?

3. How do you link to an email address?