← Structure and style a page

Attributes and links

Send people to another page with a link, and find out that its address sits inside the opening tag.

Every click you make on the web, from a search result to a shop menu, follows a link written like this.

Some words on a page should take you somewhere else. A link does that, and it is the first tag you meet that needs extra information inside it.

PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

page.html
<p>Read the <a href="https://example.com/rules">club rules</a> before you join.</p>

<a> makes a link. Read the code. What will the page show, and what happens on a click?

What will the page show, and what happens when someone clicks?

RunRun it and compare the result with your prediction.

Run

Compare the page with your prediction, then click a link (it opens in a new tab). Look for the two parts: the words that show, and the address that does not.

Code What it does Why
<a href="https://example.com/rules">club rules</a> Makes a link <a> opens it and </a> closes it. Whatever is between them is what people click
href="https://example.com/rules" Says where the link goes This is an attribute: a name="value" pair. The address is the value, in quotes
<a href="…"> The attribute sits in the opening tag Information about a tag goes inside its opening tag, after the tag name and a space. The closing tag never has one
club rules The words people click Only these show on the page. The address is not shown, and it is not what you click
page.html
<h1>Sports day</h1>
<p>Read the <a href="https://example.com/rules">club rules</a> before you join.</p>
<p>Ask your house captain for the <a href="https://example.com/timetable">timetable</a>.</p>
Try it yourselfYour edits are saved in this browser.

InvestigateTrace how each line of code connects to what you see.

Investigate

page.html
<h1>Sports day</h1>
<p>Read the <a href="https://example.com/rules">club rules</a> before you join.</p>
<p>Ask your house captain for the <a href="https://example.com/timetable">timetable</a>.</p>

Think about which part names the attribute, and where it goes.

Two of these three links work.

Which opening tag makes a link to https://example.com/join?

The page shows Timetable href=... as plain text next to a word that does not click, while the other two links work. Click the line that causes it.

ModifyChange the code on purpose and check the result.

Modify

Make the link go to https://example.com/join. The words stay the same.

Need a hint?

The address is the part inside the quotes after href=.

Another hint

Change only what is between the quotes. Leave the words alone.

Show the expected result
What the finished page looks like
What it should look like. Your words can be different.

Change the link's words to rulebook. The address stays the same.

Need a hint?

The words people click sit between <a ...> and </a>.

Another hint

Change only those words. Leave the address alone.

Show the expected result
What the finished page looks like
What it should look like. Your words can be different.

The last line has a word that should click. Make timetable a link to https://example.com/timetable.

Need a hint?

Put <a href="..."> just before the word timetable and </a> just after it.

Another hint

The address is https://example.com/timetable.

Show the expected result
What the finished page looks like
What it should look like. Your words can be different.
Try it yourselfYour edits are saved in this browser.

Change the link's address to https://example.com/join.

    This ticks when your page has all of the above.

    Change the words of the link to rulebook.

      This ticks when your page has all of the above.

      Make the word timetable a link.

        This ticks when your page has all of the above.

        InvestigateTrace how each line of code connects to what you see.

        Mix it up

        Three clubs, each a link. One of them is in the wrong place.

        Art should be the third club in the list, but it shows without a bullet and further left. Click the line that causes it.

        MakeBuild something new using what you have learned. Expect a few tries; that is normal.

        Make

        Here is a top 5 list. Change the title and the items to your own favourites (books, games, places, songs). Then make two of the items links. Use https://example.com/ followed by a name as the address, and click each link to test it.

        Try it yourselfYour edits are saved in this browser.
        Need a hint?

        Pick two items. Put <a href="..."> just inside the <li>, before the words.

        Another hint

        Close them in reverse order: </a> first, then </li>.

        Show the expected result
        What the finished page looks like
        What it should look like. Your words can be different.

        Make at least two items in your top 5 into links.

          This ticks when your page has all of the above.

          For teachers

          Students find out that a link is words plus an address in an href attribute, and that only the words show on the page. About 40 minutes.

          Open the teacher guide: answers, solutions, slides and a worksheet.

          Students will be able to

          Before class

          Read the unit primer "Lists, links and pictures in 5 minutes" first, then do the Make task yourself in the playground (about 5 minutes).

          An attribute is extra information about a tag, written inside the opening tag as name="value". href is the attribute that holds a link's address. The surprise for students is that the address does not show: only the words between <a> and </a> do. Links to example.com open a real placeholder page, so students can test a click.

          Running the lesson

          1. Predict and Run: many students pick the option where the address shows. Let them run it and click, then use Modify to change only the address and only the words, so they see the two parts are separate.
          2. Investigate: the question is about where the attribute goes. In the bug, read line 4 aloud: the text after the > is just text.
          3. Modify: three small changes: the address only, the words only, then a new link. Ask which part of the tag each change touched.
          4. Mix it up: the list bug is from last lesson. Ask what closed the list before the third item.
          5. Make: the check ticks when the page has a list with a link in it; look at the page to see that two items are links.

          The hard part (on purpose)

          Putting the attribute in the right place. Ask which part of the tag is the opening one, rather than fixing the line.

          When students get stuck

          Stretch and support

          Stretch: Make a link to one of your own other pages in the playground, or a whole sentence into a link, and test where it ends.

          Support: Give students the Modify starter and do the first task together, then link one item in the Make list.

          Where it leads

          Next lesson adds pictures, which are another tag with attributes: a name for the file and words for people who cannot see it. Class idea: show a real school page and hover over links to see the address in the browser's status bar.

          What each step is for

          Now you can
          Next lesson6. PicturesShow a picture with the img tag, and describe it with alt for anyone who cannot see it.