← Structure and style a page

Tags label text

Label text with tags, and find out that the browser ignores line breaks in your code.

Every website you have visited, from your school page to a shop, starts as text with tags like these.

Every web page is text with tags in it. A tag is a label: <h1> labels the main heading and <p> labels a paragraph. Most tags come in pairs, an opening tag <p> and a closing tag </p> with a slash, wrapped around the text they label.

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
<h1>Sports day</h1>
<p>Sports day is on Friday.
Bring a hat
and water.</p>
<p>Races start at 9 am.</p>

Read the code. Each <p> starts a paragraph and </p> ends it. How many lines of normal text will the page show?

How many lines of normal text (not counting the heading) will the page show?

RunRun it and compare the result with your prediction.

Run

Compare the page with your prediction. Then put the cursor after Bring a hat and press Enter a few times: the page does not change. Now give Bring a hat and water. its own <p> and </p>, and watch it move to a new line.

Code What it does Why
<h1>Sports day</h1> Makes the main heading <h1> opens it and </h1> closes it. The tag says what the text is; the browser picks the big, bold look
<h2>When</h2> Makes a smaller heading for one section <h1> to <h6> are all headings: the number is the level, and 1 is the biggest
<p>Races start at 9 am.</p> Makes one paragraph Each <p> starts a new paragraph, with a gap above it
the three lines inside the first <p> Show as one line The browser ignores line breaks in the code. Only a new <p> starts a new line
page.html
<h1>Sports day</h1>
<p>Sports day is on Friday.
Bring a hat
and water.</p>
<p>Races start at 9 am.</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>
<h2>When</h2>
<p>Sports day is on Friday.</p>
<h2>What to bring</h2>
<p>Bring a hat and water.</p>

What does each tag in this page do?

Tags, not lines of code, make paragraphs.

Sam pressed Enter and expected a new line.

Match each part of the page with its job.

<h1>Sports day</h1>
<h2>What to bring</h2>
<p> … </p>

A page has <p>Bring a hat.</p><p>Bring water.</p> all on one line of code. How many paragraphs does the page show?

Sam wants Bring a towel. and Races start at 9 am. on separate lines, but the page shows them on one line. Click the line that causes it.

ModifyChange the code on purpose and check the result.

Modify

Make this a notice for a different event on a different day.

Need a hint?

Change only the words between the tags. Leave the tags as they are.

Split the long paragraph so the date and what to bring are separate.

Need a hint?

End the first paragraph with </p> after Friday.

Another hint

Then start the second with <p> before Bring.

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

Add an <h2> heading above each paragraph: When above the first, What to bring above the second.

Need a hint?

A section heading uses <h2>, just like <h1> but smaller.

Another hint

Put each <h2> on its own line, just above the paragraph it describes.

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.

Split the one paragraph into two.

    This ticks when your page has all of the above.

    Add an <h2> heading above each paragraph.

      This ticks when your page has all of the above.

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

      Make

      Write a notice for an event at your school (a concert, a fair, a match): an <h1> title, two sections with <h2> headings, and a paragraph in each.

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

      Start with the <h1> title, then add one section at a time: an <h2>, then its <p>.

      Another hint

      Check the page after each tag you add. If the page looks wrong, look for a tag with a missing < or >, or a closing tag without its slash.

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

      Write a notice with a title, two headings and a paragraph under each.

        This ticks when your page has all of the above.

        For teachers

        Students label text with headings and paragraphs, and find out that the browser ignores line breaks in the code. About 40 minutes.

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

        Students will be able to

        Before class

        Read the unit primer "HTML structure in 5 minutes" first, then do the Make task yourself in the playground (about 5 minutes).

        The surprise for students: pressing Enter in the code does not make a new line on the page. Only a new <p> does. A tag is a label in angle brackets, like <p>. Most tags come in pairs: an opening tag <p> and a closing tag </p> with a slash, wrapped around the text they label.

        Running the lesson

        1. Predict and Run: most students say 4 lines. The page shows 2, because the browser joins the lines of one paragraph. Let them press Enter in the code and see that nothing changes, then add a `<p>`. Ask one pair from each answer to say why. Most will say 4: that is the idea the lesson turns around.
        2. Investigate: the match task is about meaning, not looks: `<h1>` means the main heading. The one-line question is the key idea, that the tags decide and not the lines of code.
        3. Modify and Make: one change at a time, check the page each time. The Make check ticks when the page uses `<h1>`, `<h2>` and `<p>`.

        The hard part (on purpose)

        Seeing that line breaks in the code do nothing. Let the Predict surprise land, and ask which tag starts a new line rather than fixing it.

        When students get stuck

        Stretch and support

        Stretch: Add a third section with an <h2> heading, and try <h3> and <h4> to see what the heading numbers do.

        Support: Give students the Modify starter and ask them only to change the words between the tags, then add one <h2>. Point to the Reference drawer for each tag.

        Where it leads

        Next lesson puts tags inside other tags, so a word can be important inside a paragraph, and finds out what the browser does when a tag is missing. Class idea: show a news website and ask students to spot the headings and paragraphs.

        What each step is for

        Now you can
        Next lesson2. Tags inside tagsPut one tag inside another, close the last one opened first, and find out that the browser guesses when you get it wrong.