Skip to content
engineering workbench.by StudyPort Academy
Learning path
Intermediate16 minLESSON 09 / 16

Display types

Change a control, or edit the CSS. The preview uses that same CSS.

display

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.

What each display value changes
ValueWhere it applies in the demoWhat you should see
blockEach itemIts own line. Width and height are honored
inlineEach itemFlows in the sentence. Width and height are ignored
inline-blockEach itemFlows in the sentence, and width and height are honored
flexThe parentThe children become flex items in a row or column
gridThe parentThe 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.

04

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.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

flex
3
Oak
div

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01Where do you set display flex?
    02Which value keeps a box in the line and still honors width?

    Ready to call this one understood?

    Mark this lesson complete to earn 150 XP. You can always revisit it.

    Sign in to save progress
    Next lesson