Aral Code

Layout Lesson 16 of 33

CSS Display — block, inline, inline-block and none

The display property decides how an element sits on the page. Learn block, inline, inline-block and none, plus the difference between display none and visibility hidden.

Every element has a display value that decides how it behaves in the layout: does it start on a new line? Can it have a width? Does it sit next to other elements? Understanding display explains a lot of "why won't this move?" moments.

block

Block elements start on a new line and stretch to fill the full width available, like paragraphs in a document. Examples: div, p, h1–h6, ul, li, section, header, footer, form.

  • They stack on top of each other.
  • width, height, margin and padding all work fully.

inline

Inline elements sit inside a line of text and are only as wide as their content, like words in a sentence. Examples: span, a, strong, em, code.

  • They flow side by side with text, and wrap to the next line when needed.
  • width and height are ignored.
  • Left and right padding and margin work, but top and bottom ones don't push other lines away.
Example Block vs. inline
<style>
  div, p { background: #e3f1ec; border: 1px solid #0f5c4d; margin: 4px 0; }
  span { background: #fdf3dc; border: 1px solid #f2b33d; width: 300px; height: 80px; }
</style>
<div>I'm a div (block)</div>
<p>I'm a paragraph (block). Inside me, <span>I'm a span (inline)</span> and <span>another span</span> sit in the line.</p>

The spans have width: 300px and height: 80px, but they ignore both, because they are inline.

Changing the display

You can change any element's display with CSS. The HTML element keeps its meaning; only its layout behavior changes.

Example Making list items sit in a row
<style>
  li { display: inline; margin-right: 16px; font-family: Arial, sans-serif; }
</style>
<ul>
  <li>Home</li>
  <li>About</li>
  <li>Contact</li>
</ul>

inline-block: the best of both

inline-block elements sit side by side like inline elements, but respect width, height, and all padding and margins like block elements. It's perfect for buttons, badges, and small cards in a row.

Example inline vs. inline-block
<style>
  .tag { background: #0f5c4d; color: white; padding: 10px 14px; margin: 4px; }
  .ib { display: inline-block; width: 110px; text-align: center; border-radius: 8px; }
</style>
<p>inline: <span class="tag">HTML</span><span class="tag">CSS</span><span class="tag">JS</span></p>
<p>Notice how the inline tags' padding overlaps the lines above and below when the text wraps.</p>
<p>inline-block: <span class="tag ib">HTML</span><span class="tag ib">CSS</span><span class="tag ib">JS</span></p>

display: none

display: none removes an element completely. It's not shown, and it takes up no space, as if it weren't in the HTML at all. JavaScript often switches between none and block to show and hide things like menus and pop-ups.

visibility: hidden

visibility: hidden also hides an element, but it still takes up its space, leaving an empty gap.

Example display none vs. visibility hidden
<style>
  .box { padding: 10px; margin: 4px 0; background: #e3f1ec; font-family: Arial, sans-serif; }
</style>
<div class="box">Box 1</div>
<div class="box" style="display: none;">Box 2 (display: none)</div>
<div class="box">Box 3</div>
<hr>
<div class="box">Box 1</div>
<div class="box" style="visibility: hidden;">Box 2 (visibility: hidden)</div>
<div class="box">Box 3</div>

In the first group, Box 3 moves up into Box 2's place. In the second group, there's an empty gap where Box 2 used to be.

The modern display values

display also switches on the two modern layout systems, which you'll learn next:

  • display: flex — Flexbox, for arranging items in a row or a column
  • display: grid — CSS Grid, for arranging items in rows and columns at the same time

Before Flexbox and Grid existed, developers built layouts with inline-block and float, which was tricky. Today, Flexbox and Grid make layout much easier, so we'll spend several lessons on them.

Quick reference

ValueNew line?Width/height work?Typical use
blockYesYesSections, paragraphs, containers
inlineNoNoWords and links inside text
inline-blockNoYesButtons, badges
noneNot shown, takes no spaceHidden menus, closed pop-ups
flexYes (the container)YesRows/columns of items
gridYes (the container)YesFull page layouts, galleries

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Which of these is an inline element by default?
2. You set width: 200px on a <span> and nothing happens. Why?
3. Which value lets elements sit side by side AND have a width and height?
4. What is the difference between display: none and visibility: hidden?

By Sir Reyel · Last updated 2026-12-04