Find out why paragraphs stack while bold words sit in a line, and use div and span to group things you want to style.
Every menu, card and banner on a website is a plain box that someone decided should stack or sit in a line.
Some parts of a page start on a new line, like a paragraph. Others sit inside a line of text, like a bold word or a link. Which kind an element is decides how it fills the page.
Make your prediction first. Help opens once you've locked it in.
<style>
.mark {
background-color: gold;
}
</style>
<h2>Sports day</h2>
<p>Races start at <span class="mark">9 am</span> on the oval.</p>
<div class="mark">Bring a hat and water.</div>
<p>Read the <a href="https://example.com/rules">rules</a> first.</p>
<span> and <div> are tags you have not met. Both are plain boxes that the class mark colours gold. Read the code. How wide is the gold in each place?
Compare the page with your prediction. Then change span to div (in the opening and closing tag): 9 am jumps onto its own line. Change it back. The last link is an inline <a>, yet it takes a whole line, because its class sets display: block;. Add display: block; to the .mark rule too: the span now stacks like a div.
| Code | What it does | Why |
|---|---|---|
<p>, <h2>, <div> |
Start on a new line and take the full width | These are block boxes. That is why the gold behind the div runs across the page |
<strong>, <a>, <span> |
Sit inside a line of text | These are inline boxes. They are only as wide as their words, and the gold stops there |
<span class="mark">9 am</span> |
A plain box inside a line | A span has no look of its own. It is for a few words you want to style |
<div class="mark">…</div> |
A plain block box | A div has no look of its own. It is for grouping several elements so you can style them as one |
display: block; |
Makes any element a block | display sets which kind of box an element is. display: inline; does the opposite |
<style>
.mark {
background-color: gold;
}
.stack {
display: block;
}
</style>
<h2>Sports day</h2>
<p>Races start at <span class="mark">9 am</span> on the oval.</p>
<div class="mark">Bring a hat and water.</div>
<p>Read the <a href="https://example.com/rules">rules</a> first.</p>
<a class="stack" href="https://example.com/join">Join the club</a>
<div>
<p>Bring a hat.</p>
<p>Bring water.</p>
</div>
The two paragraphs are wrapped, and no rule mentions the div.
Pick the tags that sit inside a line.
Each label should sit above its box.
Labels are inline, so each one sits beside its box.
Add display: block; to the label rule.

One <div> around both paragraphs, and one rule for it.
Wrap both paragraphs in one div that has the class. The div needs a closing tag after the second paragraph.
Then write a .packing rule with a background-color.

Put each label on its own line, above its box.
This ticks when your page has all of the above.
Group the two paragraphs in a div with the class packing, and give it a background colour.
This ticks when your page has all of the above.
The words in the div and in the span should both be crimson and 20px. Right now they are navy and normal size. Change the page so both are crimson and 20px.
<style>
.alert {
color: crimson;
}
span, div {
color: navy;
}
</style>
<div>Bring a hat and water.</div>
<p>Races start at <span>9 am</span> sharp.</p>

Mark the div and the span with the class alert, and make both 20px.
This ticks when your page has all of the above.
Highlight the most important phrase in this concert notice. Put a <span> with the class highlight around just those words, and write a .highlight rule with a background colour.
A span goes around only the words you want to mark, and it takes the class you will style.
Then a <style> block with a .highlight rule and a background-color.

Highlight a phrase with a span and a class.
This ticks when your page has all of the above.
Students find out that block elements start a new line and take the full width while inline ones sit in the line, that div and span are plain boxes for grouping, and that display switches between block and inline. About 40 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Read the unit primer "Layout and components" first, then do the Make task yourself in the playground (about 5 minutes).
A block box starts on a new line and takes the full width of its container. An inline box sits inside a line of text and is only as wide as its content. <div> (block) and <span> (inline) are plain boxes: they have no look until a rule styles them. display: block; and display: inline; swap the kind. This lesson uses background colour to show the width, because box properties such as padding and borders come next lesson.
Believing a div adds a look. Ask what the div would have to be told before anything on the page looked different.
Stretch: Make the three links in a nav stack on their own lines with display: block, then make three paragraphs sit in a line with display: inline. Which is easier to read?
Support: Give students the Run page and ask them only to swap span and div and say what moved.
Next lesson gives each box padding, a border and a margin, and works out how wide the box is. Class idea: open a news site and find three block boxes and three inline ones.