The Display Property
What is Display?
The display property controls how an element behaves in the
document flow. It's one of the most important CSS properties for layout.
Display: Block
Block elements take up the full width available and start on a new line.
Examples: <div>, <p>,
<h1>.
Display: Inline
Inline elements only take up as much width as needed and don't start on
a new line. Width and height have no effect. Examples:
<span>, <a>,
<strong>.
Display: Inline-Block
Inline-block combines both behaviors: elements flow inline but respect width and height. Perfect for creating horizontal layouts!
Display: None
display: none completely removes the element from
the page. It takes up no space.
Changing Default Display
You can change an element's default display behavior. For
example, make a <span> behave like a
block element.
•
block - Full width, new line•
inline - Content width, same line•
inline-block - Content width, same
line, respects width/height•
none - Hidden, no space
Common Use Cases
- Navigation menus - Use
inline-blockfor horizontal menu items - Image galleries - Use
inline-blockfor side-by-side images - Hide elements - Use
display: nonefor mobile menus, modals - Button groups - Use
inline-blockfor buttons in a row
Quick Quiz
Which display value allows elements to sit side-by-side AND respect width/height?
Enjoying these tutorials?