Controlling Layout: The CSS `display` Property

Discover the fundamental property that controls layout. Learn to use `block`, `inline`, `inline-block`, and `none` to structure your webpage.

Lesson ProgressStep 1 of 9
Block Element

This is text with a Inline Element inside.

Inline-Block
Inline-Block
This will disappear
0 EXP

Hello! Let's explore the `display` property, the most important CSS rule for controlling layout.

/* Welcome to the CSS Layout Simulator */

Understanding `display: block`

An element with display: block is a foundational building block. It always starts on a new line and takes up the full width available to it, stretching to fill its parent container.

Crucially, block elements respect all box model properties: width, height, margin, and padding. This makes them ideal for major layout sections, paragraphs, and headings.

Default Block Elements: <div>, <p>, <h1>-<h6>, <ul>, <li>, <section>, <article>, <nav>.

System Check

Which of these is NOT a block-level element by default?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🏆
Display Master

Master the core CSS display values: block, inline, and inline-block.

🏗️
Layout Whiz

Correctly structured a layout using different display properties.

✍️
Syntax Expert

Prove your mastery of CSS `display` property syntax.

Mission: Build a Horizontal Navigation Bar

By default, list items (`li`) are `display: block`. Modify the CSS to make the `li` elements in the `nav` line up horizontally. Using `inline-block` or `flex` are both valid solutions.

A.D.A. Feedback:

> System integrity looks stable. Code is valid.

Challenge: Order the Layout

Drag the elements into the correct visual order as they would be rendered by the browser from top to bottom.

<span>I am inline.</span>
<div>I am a block.</div>
<span>I am also inline.</span>

Challenge: Complete the Syntax

Fill in the missing property and value to completely hide the element from the layout.

.hide-me {:;}

Consult A.D.A.

Community Holo-Net

Mastering the Flow: A Deep Dive into the CSS 'display' Property

The CSS `display` property is arguably the most important and fundamental property for controlling layout on the web. It dictates how an element is rendered in the document, how it interacts with its neighbors, and how its children are organized. Understanding its values is the first true step toward mastering CSS layout.

At its core, `display` defines an element's **outer display type** (how it behaves in relation to other elements) and its **inner display type** (how it organizes its own children). Let's break down the most critical values.

The Legacy Values: `block` and `inline`

These are the two original display values that form the basis of "Normal Flow" in HTML.

  • display: block: This makes an element a "block-level" element.
    • It always starts on a new line.
    • It takes up the full width available to it (stretches to fill its container).
    • It fully respects width, height, margin, and padding properties.
    • Common default block elements include: <div>, <p>, <h1>-<h6>, <ul>, <li>, and <section>.
  • display: inline: This makes an element an "inline-level" element.
    • It does *not* start on a new line; it flows with text.
    • It only takes up as much width as its content needs.
    • It **ignores** width and height properties.
    • Vertical margin and padding are not fully respected (they won't push other elements away).
    • Common default inline elements include: <span>, <a>, <strong>, and <em>.

The Hybrid: `inline-block`

This value provides a crucial middle ground. An element with display: inline-block is the best of both worlds:

  • Outer Display: It behaves like an inline element, flowing with text and not forcing new lines.
  • Inner Display: It behaves like a block element, fully respecting width, height, margin, and padding.

This makes it perfect for navigation menu items, buttons, or any set of items you want to line up horizontally while controlling their size.

⚠️ The `inline-block` Whitespace Quirk

Because inline-block elements flow like text, they also respect whitespace in your HTML code (like line breaks between <li> tags). This creates a small, visible gap between elements. A common fix is to set font-size: 0 on the parent container and reset the font-size on the children.

✔️ Good Practice

.nav-item {
  display: inline-block;
  width: 100px;
  padding: 10px;
}

Perfect for creating a row of sized boxes.

Hiding Elements: `none` vs. `visibility`

How you hide an element has massive implications for your layout.

  • display: none: This **completely removes the element from the document**. It takes up no space, and the layout reflows as if the element never existed. It is also removed from the accessibility tree, meaning screen readers will not find it.
  • visibility: hidden: This makes the element invisible, but it **still occupies its original space in the layout**. You're left with an empty, blank box.

The Modern Era: `flex` and `grid`

These values turn an element into a **container** that controls its children in a new, powerful way.

  • display: flex: Turns the element into a "flex container." Its direct children become "flex items" and are arranged in a one-dimensional row or column, with powerful alignment and spacing capabilities. This is the modern standard for most component layouts.
  • display: grid: Turns the element into a "grid container." Its children become "grid items" and can be arranged in a two-dimensional system of rows and columns. This is the standard for complex, page-wide layouts.

Other Notable Values

  • display: contents: A "magical" value. It removes the element's box entirely, but *not* its children. The children are "promoted" one level up in the layout tree. This is an advanced technique, often used to make semantically- nested elements work inside a flex or grid container.
  • display: table, table-cell, etc.: These values force elements to mimic the behavior of HTML table elements. This was a common layout hack before Flexbox and Grid, but should now be avoided for layout.
Key Takeaway: Use the right tool for the job. Use block and inline for the natural flow of document content. Use inline-block for simple horizontal menus. Use flex for component-level layouts (rows of cards, forms) and grid for page-level layouts (headers, sidebars, content).

CSS Display Property Glossary

display
The fundamental CSS property that specifies an element's rendering box and its layout behavior (its outer display type and inner display type).
block
A display value. The element starts on a new line and takes up the full width available. It respects all box-model properties like width, height, margin, and padding.
inline
A display value. The element flows with surrounding text and does not start on a new line. It only takes up as much width as its content needs. It ignores width and height.
inline-block
A hybrid display value. The element flows inline (like text) but respects width, height, margin, and padding (like a block element).
none
A display value. The element is completely removed from the document flow and the accessibility tree. It takes up no space, and the layout reflows as if it never existed.
flex
A display value that turns an element into a Flexbox container. This enables a one-dimensional layout model for its children, allowing for powerful alignment and spacing.
grid
A display value that turns an element into a Grid container. This enables a two-dimensional layout model of rows and columns for its children.
Normal Flow
The default layout behavior of elements on a webpage (also called "Document Flow"). Block elements stack vertically, and inline elements flow horizontally with text.
Block-level Element
An element that has display: block by default, such as <div>, <p>, or <h1>.
Inline-level Element
An element that has display: inline by default, such as <span>, <a>, or <strong>.
visibility: hidden
A property often confused with display: none. This makes an element invisible, but it still occupies its full space in the layout.
contents
An advanced display value. It removes the element's own box, but *not* its children. The children are "promoted" and act as if they were direct children of the element's parent.
list-item
The default display value for <li> elements. It behaves like block but also generates a list marker (a bullet or number).

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching CSS and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest CSS specifications (including Flexbox and Grid) and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!