Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Link Pages Together

In this video, you linked the garden’s home page and its new plots page to each other, to a section by its id, and to Rosa’s email.

Key Points

  • A link is an <a> element, short for anchor. The words between its tags are the link text, which the browser shows underlined by default. It’s blue until you’ve visited the link, and purple after.
  • The href attribute says where clicking the link goes:
  • plots.html: a file name on its own means a file in the same folder as the current page.
  • #seed-swap: a hash sign and an id point at that element on the current page. The address gains #seed-swap, and on a page longer than the window, the browser scrolls that element into view.
  • index.html#work-day: a file name, then a hash sign and an id. The browser loads the file, then finds the element with that id.
  • mailto:[email protected]: the browser hands the address to whatever handles email on the visitor’s system. That’s often a mail app or webmail with a new message to Rosa. With nothing set up, the visitor might get a chooser, or nothing at all. The address itself is the link text, so every visitor can still read it. A tel: link works the same way for a phone number, and a phone offers to call.
  • Make link text name where the link goes. Screen reader users often jump from link to link, or list them all, and hear each link without its sentence. A page full of “click here” links tells them nothing.
  • You may also see target="_blank" on a link. It opens the link in a new tab or window. Use it sparingly, and leave it off between your own pages, since visitors can already open any link in a new tab themselves when they want one.

Final Code

Your home page and plots page now link to each other. Here’s index.html, the home page, with its link to the plots page, its jump to the seed swap section, and Rosa’s address as a mailto: link:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Rosa’s garden folder holds a few pages now: the home page, her watering rota and the work day notice. But nothing links them. In this video, you’ll link pages together, so visitors can move around the site by clicking.

00:14 Rosa wants another page, about the plots. Create plots.html next to the home page, in your garden folder. It gets the same skeleton, a heading, and a line on who tends the first plots.

00:27 Your live preview serves both pages. But a visitor on the home page can’t reach the plots page unless they type its address. The pages need links.

00:38 A link is an <a> element. The a stands for anchor. On the home page, add a paragraph. Then wrap its last four words in an anchor element.

00:49 The href attribute says where the link goes. Here, that’s the plots page’s file name. A file name on its own means a file in the same folder as this page.

01:01 Save, and the words between the tags turn blue and underlined, the browser’s default for a link. Once you’ve visited it, it turns purple. Click it, and the browser loads the plots page.

01:12 The address now ends with the plots page’s file name.

01:17 On the plots page, add a link back to the home page. Its href is index.html, the home page’s file. Click it, and you’re home again. Look at the link text.

01:30 Each one names where it goes. Screen reader users often jump from link to link, or list them all, and hear each one without its sentence. A page full of click here links tells them nothing.

01:43 A link can also point at one part of a page. The seed swap heading on the home page has an id, seed-swap, from when you named it. For the href, write the id with a hash sign in front.

01:56 With no file name, the link stays on the current page. Click it, and the address gains a hash and the id. Rosa’s page is short and fits the window, so nothing scrolls.

02:08 On a page longer than the window, the browser scrolls that heading into view.

02:14 Now combine the two. On the plots page, this link’s href has a file name, a hash sign, and an id, one after another. Your turn: pause the video and predict. Where does this link take you?

02:34 To the home page, at its work day heading. The browser loads the file first, then finds the element with that id.

02:43 Rosa’s contact line is still plain text at the bottom of the home page. An href can hold an email address too. Start it with mailto and a colon, then the address.

02:55 Make the address itself the link text. Click it, and the browser hands the address to whatever handles email on your system. That’s often a mail app or webmail with a new message to Rosa.

03:06 With nothing set up, you might get a chooser, or nothing at all, but the address is still there to read. A tel link works the same way for a phone number. On a phone, tapping it offers to call.

03:21 A link is an anchor element. Its href says where clicking goes: a file, a hash and an id, or mailto and an address. Its text names where it goes, even when it’s heard on its own.

03:35 So far, every page sits in one folder. Next, in Follow Relative Paths, you’ll see how an href finds a file in another folder.

Become a Member to join the conversation.