← Web basics: HTML, CSS and JavaScript

Links

Connect pages with <a href>, and open new tabs safely.

Start this lesson

Links are what make the web a web. A link is an <a> element (a for "anchor") with an href attribute holding the address to go to. The text between the tags is what people click, so it should say where the link goes. An address starting with https:// goes to another site; a short one like about.html goes to a page on the same site; one starting with # jumps to an element with that id on the same page.

<a href="https://www.openstreetmap.org">See the free world map</a>
<a href="contact.html">Contact us</a>
<a href="#prices">Jump to prices</a>

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

The first link leaves the site, the second stays on it, the third scrolls to the element with id="prices". The last one opens in a new tab: target="_blank" does that, and rel="noopener noreferrer" stops the new page from controlling or tracking the page it came from.

Avoid link text like "click here". Screen reader users often hear a list of links on their own, and ten "click here" links tell them nothing. Write "Download the bus timetable" instead.

Opening new tabs can confuse people, so do it only when it really helps (for example, a help page while they fill in a form), and say so in the text.