YOUR SAVED CODE-ALONG
Compare block, inline and inline-block: code-along workspace
Keep the lesson open on your other screen. Your edits stay in this workspace, separate from the practice activity. Sign in to save and reload a private account draft across devices, or share a snapshot when you need help.
CODE-ALONG / THEATER MODE
Compare block, inline and inline-block
ORIGINAL WALKTHROUGH · 9:36
Watch with Rob.
Pause whenever you want to try a change. You can return to the lesson at any time.
You are signed in, but video access needs attention. Check your account access. Your saved work is kept.
Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.
Video settings & progress
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.
Start the video to enable typing controls.
YOUR TURN
Code along: CSS display property
Follow the video in index.html. Add the demonstrated HTML and edit CSS inside its style element. This is a code-along, so there are no automatic challenge checks.
Load an example, edit it and run it. Word wrap is enabled.
Your check results
Lesson reference
Examples load into this same code-along only after you confirm replacing your code.
Display changes the box, not the meaning
The browser lays out HTML as boxes. The display property tells it how a box participates in layout. You can change a span’s display without turning that span into a heading, paragraph or section. Choose meaningful HTML first, then choose its visual behavior.
This lesson uses normal document flow. Flexbox and Grid change how their children are laid out, so they are intentionally absent from these examples.
Block: start a new line
A block box starts on a new line in normal flow. With an automatic width, it normally fills the available width of its containing block. That might be a small section, not the entire browser.
You can set its width and height. A block with a smaller width still starts on a new line, even if another block could fit beside it. Paragraphs, headings and div elements normally start as blocks.
<div class="notice">Bring a notebook.</div>
<div class="notice">Take a break.</div>Inline: highlight a word without splitting the sentence
An ordinary span starts inline. It flows with neighboring words rather than forcing a block-level line break. Use it to style a word or short phrase while keeping that text in its sentence.
For an ordinary non-replaced inline span, width and height do not size its box. A blue word can remain small even when those declarations are in your CSS. That does not mean the stylesheet is disconnected. This rule is about text spans, not every inline element, such as an image.
<p>Bring a <span class="highlight">curious</span> mind.</p>Inline-block: a sized box within the line
Use display: inline-block when a small label should participate in the line but also accept width, height and box spacing. Several labels can sit side by side when the line has enough room. They can wrap when the line is too narrow.
Do not use this as a promise that everything will always stay on one row. Later, Flexbox and Grid will give you more tools for whole layouts. Here we are learning the behavior of individual boxes.
.tag {
display: inline-block;
width: 96px;
height: 32px;
}Explore one change in the preview
Use Next to switch the same blue label between the three display values. The highlighted declaration is the only change. Watch whether the sentence splits and whether the requested 100px by 60px box becomes visible.
One span, one sentence and the same requested dimensions. Switch display to compare normal-flow layout. No Flexbox or Grid parent.
<p>Pick a <span class="label">study</span> partner.</p>.label {
background-color: #b9e8fa;
width: 100px;
height: 60px;
display: inline;
}<p>Pick a <span class="label">study</span> partner.</p>.label {
background-color: #b9e8fa;
width: 100px;
height: 60px;
display: block;
}<p>Pick a <span class="label">study</span> partner.</p>.label {
background-color: #b9e8fa;
width: 100px;
height: 60px;
display: inline-block;
}YOUR PAGE PREVIEW
Inline: no forced new line; these dimensions are ignored
Stage 1 of 3
Inline follows the sentence
The blue study label stays in the sentence. Its width: 100px and height: 60px declarations do not size this ordinary inline span. The blue background hugs the word.
Use Next to explore at your pace, or Play demo for a five-second pause between stages.
Your turn: arrange study-session labels
Practice with orange notices, one blue word in a sentence and two purple snack labels. You will compare line breaks, try dimensions on an inline span, then give the snack labels sized boxes and spacing.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)6 steps · Saved work · Instant feedback
Padding is inside; margin is outside
Padding adds room inside the colored box; margin separates it from neighboring boxes. In the default content-box sizing used in this practice, a width of 100px plus 8px of padding on each side produces a box 116px wide, before borders. Margin-right adds outside space beyond that box.
Inline vertical padding can paint outside a text line without making the line taller in the way you expect. When the exercise needs a predictable sized label, use inline-block.
Debugging task: repair the study-room labels
The page below has two wrong display values. The highlighted word splits its sentence, and the purple labels ignore their dimensions. Change only the two display declarations named in the task checklist. The checks measure both labels, including their visible box dimensions.
See the attached lesson’s comic
