Display types
Change a control, or edit the CSS. The preview uses that same CSS.
Numeric changes ease so you can watch them.
Switching the control changed how Oak, Pine, and Fern share the line. Block stacked them, inline let them sit in the sentence, and flex or grid moved the display onto the parent so the children became items in that mode.
+Go deeper
Block stacks
A block box starts on a new line and stretches to the containing block. A div and a p do this unless you change display. The still wraps the box. Display only decides how it sits among its siblings.
Inline stays in the line
Inline boxes sit in the line of text. Width and height on an inline box are ignored. Vertical margin does not push the line the way it does for a block. A span is inline by default. A link is too.
Inline block keeps a box
inline-block stays in the line and still honors width, height, and vertical margin. That is the useful middle when you want a sized box that does not force a new line.
| Value | Where it applies in the demo | What you should see |
|---|---|---|
| block | Each item | Its own line. Width and height are honored |
| inline | Each item | Flows in the sentence. Width and height are ignored |
| inline-block | Each item | Flows in the sentence, and width and height are honored |
| flex | The parent | The children become flex items in a row or column |
| grid | The parent | The children are placed on a grid |
Flex and grid are parents
display flex and display grid belong on the parent. The children become items in that formatting context. Their own display is blockified. The rules that distribute space inside those modes are the next two lessons. You do not need them to see that the parent changed.
Look at the siblings
Watch the sentence around the items when you change the control. If the words Walk and today break onto their own lines, the items became blocks. If the items line up in a row with a gap, the parent became flex or grid.
Guided challenge
Display types
The stage style says display flex. The script still logs block. Read the style attribute and log flex when that word is there.
Your console output appears here.
EXPECTED CONSOLE OUTPUT
flex 3 Oak div
Hints 0/2
Use all hints or make 3 failed runs (0/3).
Free sandbox
Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.
Your console output appears here.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 150 XP. You can always revisit it.