Back to course

Lesson 11: Creating Hyperlinks (The Anchor Tag `<a>`)

The HTML Masterclass: From Zero to Web Developer

11. Creating Hyperlinks (The Anchor Tag <a>)

Hyperlinks (or links) are the 'HyperText' part of HTML, connecting documents together. The anchor tag, <a>, is used to create them.

11.1 Essential Attributes: href

The most important attribute for the anchor tag is href (Hypertext Reference), which specifies the destination URL.

html

<p> Visit the official <a href="https://www.w3.org/">W3C website</a> for standards information. </p>

11.2 Opening Links in a New Tab

To prevent the user from leaving your site when clicking an external link, use the target attribute set to _blank.

html <a href="https://google.com" target="_blank">Search Google (Opens in new tab)</a>

11.3 Email Links

Use mailto: in the href to prompt the user's email client to open, pre-addressed to the specified email.

html <a href="mailto:support@example.com">Contact Support</a>