← Structure and style a page

Tags inside tags

Put one tag inside another, close the last one opened first, and find out that the browser guesses when you get it wrong.

A news page puts a link inside a headline inside a box inside a page. Tags inside tags are how every page is built.

Last lesson each tag stood on its own. A tag can also go inside another tag. Two new ones to try: <strong> marks important words (the browser makes them bold) and <em> marks stressed words (the browser slants them).

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>Bring <strong>a hat, <em>water</em> and sunscreen</strong> on Friday.</p>

Read the code. The <em> sits inside the <strong>. Which words will look both bold and slanted?

Which words will look both bold and slanted?

RunRun it and compare the result with your prediction.

Run

Compare the page with your prediction. The Boxes view draws each tag as a box: <em> sits inside <strong>, which sits inside <p>. Then wrap the word Friday in <em> and </em> yourself.

Code What it does Why
<strong>a hat</strong> Marks important words The tag says the words matter; the browser picks bold
<em>water</em> Marks stressed words The browser picks slanted text
<strong>a hat, <em>water</em> and sunscreen</strong> One tag inside another The tag opened last closes first, like boxes inside boxes: </em>, then </strong>, then </p>
<strong>a <em>hat</strong></em> Tags that cross No error message appears. The browser makes its best guess, which may not be what you meant, so check the page
<!-- a note --> A comment The browser ignores it, so it is a note to yourself in the code
page.html
<h1>Sports day</h1>
<p>Bring <strong>a hat, <em>water</em> and sunscreen</strong> on Friday.</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>Bring <strong>a hat and
<em>water</strong> on Friday</em>.</p>

The tags cross in one line.

A closing tag is missing from this page.

<p>Bring a <strong>hat.</p>
<p>Wear sunscreen.</p>
<p>Races start at 9 am.</p>

Sam wants a hat and water bold, with water also slanted. The end of the paragraph looks wrong, but nothing reports an error. Click the line where the tags cross.

The first paragraph is missing its </strong>. Fill in whether each line of text looks bold.

textbold?
Bring ano
hat.yes
Wear sunscreen.
Races start at 9 am.

ModifyChange the code on purpose and check the result.

Modify

Swap the closing tags so the last one opened closes first.

Need a hint?

<em> was opened last, so it must close first.

Another hint

Swap the two closing tags after water: </em></strong>.

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

Make the word Friday important and stressed, with <strong> outside and <em> inside.

Need a hint?

Put one tag outside and the other inside, and close them in the reverse order.

Another hint

Close them in reverse order.

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.

Close the tags in the right order.

    This ticks when your page has all of the above.

    Make Friday both important and stressed.

      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

      Finish this school trip notice. Mark the most important words with <strong>, and one word inside them with <em>, closing </em> right before </strong>.

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

      Pick the words that matter most and wrap them in <strong> and </strong>.

      Another hint

      Inside those words, wrap one word in <em> and </em>. Close </em> before </strong>.

      Another hint

      Turn on Boxes: every <em> box should sit fully inside a <strong> box.

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

      Mark important words with <strong>, and one stressed word with <em> inside them.

        This ticks when your page has all of the above.

        For teachers

        Students put one tag inside another, close the last one opened first, and find out that the browser guesses silently when tags are missing or cross. 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 idea: nesting. Tags go inside other tags like boxes inside boxes, so the tag opened last must be closed first. Turn on Boxes in the playground and every tag becomes a box, which shows the nesting.

        Unlike Python, HTML never stops with an error. A missing or crossed tag gives a page that looks wrong, and the browser says nothing.

        Running the lesson

        1. Predict and Run: many students think only water changes, or that the inner tag cancels the outer one. Turn on Boxes and ask which boxes water sits in. Ask the pairs who chose option 3 why they think the inner tag cancels the outer one.
        2. Investigate: the crossing is on one line. Ask which tag was opened last and whether it closed first. The missing `</strong>` trace is the surprise: the bold runs on into the next paragraphs and no message appears.
        3. Modify and Make: one change at a time, check the page each time. In Boxes, a correct page has every box fully inside another.

        The hard part (on purpose)

        Closing tags in the right order. Turn on Boxes and ask which box is inside which, rather than correcting the tags.

        When students get stuck

        Stretch and support

        Stretch: Put <em> inside <strong> inside <p> inside nothing else, then draw the boxes on paper. Add a comment above each paragraph with <!-- -->.

        Support: Give students the Modify starter and ask only for the first task: swap two closing tags. Use Boxes to show the boxes cross.

        Where it leads

        Next lesson adds CSS: a rule can style every tag of one kind at once, and nesting is what lets it colour just the important words. Class idea: show a news website with the page source open and spot tags inside tags.

        What each step is for

        Now you can
        Next lesson3. Rules and selectorsWrite a CSS rule that styles every tag of one kind, and find out that it changes how they look, not what they are.