HTML Link Attributes: href and target

Learn how to use the href and target attributes to control your links' destination and behavior.

Link Attributes: The GPS for your Links

You know how to create a link with `<a>`, but how do you control it? Attributes are like the GPS instructions that tell your links where to go and how to get there.

The 'href' Attribute

The href attribute specifies the URL of the link's destination. It can be an absolute URL (like `https://www.google.com`) or a relative URL to another page on the same site (like `/about.html`).

The 'target' Attribute

The target attribute controls where the link opens. Using target="_blank" is a common practice for external links, as it keeps your site open in the original tab.

Practice Zone


Interactive Test 1: Drag & Drop

Arrastra en el orden correspondiente.


Arrastra las opciones:

="_blank">Link</a>
href="https://www.example.com"

Completa el código:

<a______
target______

Interactive Test 2: Fill in the Blanks

Rellena los huecos en cada casilla.

<a  >Link Text</a>

Practice Example: Code Editor

Create a link that opens in a new tab and directs to `https://www.google.com`. Make sure to use both the `href` and `target` attributes.

* Write the code below. Correct characters will be shown in green and incorrect ones in red.

<a href="https://www.google.com" target="_blank">Visit Google</a>

Knowledge Check

Which attribute is used to specify the destination of a link?