Display
Control how elements behave, how much space they occupy, and how they flow on the page.
display: inline;
display: inline-block;
display: none;
>_ What Does Display Do?
The CSS display property controls how an element participates in the layout of a webpage — including whether it starts on a new line, sits beside other elements, accepts dimensions, or appears at all.
HTML elements already have default display behavior. For example, headings and paragraphs normally behave differently from links and spans.
CSS lets us change that behavior.
Block
Starts on a new line and normally expands across the available width.
Inline
Flows within surrounding text and uses only the space its content needs.
Inline-block
Sits beside other elements while still allowing width and height.
None
Removes the element from the page’s rendered layout.
>_ display: block
A block element starts on a new line and normally takes up the available width of its container.
display: block;
}
>_ display: inline
Inline elements flow alongside surrounding content instead of automatically starting a new line.
display: inline;
}
>_ display: inline-block
inline-block combines useful characteristics of both block and inline elements.
Elements can remain beside each other while also accepting properties such as width and height.
display: inline-block;
width: 120px;
}
>_ display: none
Setting an element to display: none removes it from the rendered layout.
display: none;
}
Unlike making something transparent, an element using display: none does not reserve its normal space in the layout.
>_ Quick Reference
display: block;
Starts on a new line and normally fills the available width.
display: inline;
Flows with surrounding content and does not behave like a full-width block.
display: inline-block;
Sits inline while allowing dimensions such as width and height.
display: none;
Removes the element from the rendered layout.
HTML elements have default display behavior,
but CSS can change it. A
<span> can become block,
and a <div> can become
inline — although you should still choose
HTML elements based on their meaning.
Control the Layout
Style four groups of elements using different display values and compare how they behave.
-
✓
Set the
.block-itemelements to block. -
✓
Set the
.inline-itemelements to inline. -
✓
Set the
.boxelements to inline-block. -
✓
Give each
.boxa width. -
✓
Hide the
.secretelement with display: none. - ✓ Experiment by changing one display value and observe the layout.
Display Challenge
What You’ve Learned
display property controls
how elements participate in layout.
block elements begin on
a new line and normally use available width.
inline elements flow
alongside surrounding content.
inline-block can sit
beside other elements while accepting dimensions.
display: none removes
an element from the rendered layout.
Nice work!
Finished this lesson? Mark it complete to track your progress.


