Links & Navigation

Hyperlinks with the Anchor Tag

How to link to webpages, files, and element IDs.

Hyperlinks are defined with the <a> (anchor) tag. The destination address is specified in the href attribute.

The Anchor Tag

  • href: Defines the URL to navigate to.
  • target: Controls where to open the link (e.g. _blank opens a new tab).
  • rel: Security parameters (e.g. noopener noreferrer).

Example

html
<a href="https://google.com">
Google
</a>

Interview questions

Sign in to save

Why is rel='noopener noreferrer' important when using target='_blank'?

It prevents security vulnerabilities by ensuring the newly opened page cannot access the referring window via the `window.opener` object, which protects against reverse tabnabbing attacks.

Practice

Write an anchor link that points to Google and opens in a new tab securely.

Hint: Set target to '_blank' and rel to 'noopener noreferrer'.