What Is the CSS Display Property and How Does It Work?

Learn What Is the CSS Display Property and How Does It Work? with practical examples, explanations, best practices, and real-world coding techniques.

Try Editor

What Is the CSS display Property?

The CSS display property determines how an element participates in layout and how its contents are laid out. It is one of the most important CSS properties because changing display can completely change how an element behaves on the page.

For example, an element can behave like a block-level element, sit inline with surrounding content, create a Flexbox container, create a Grid container, or be removed from layout entirely with display: none.

Understanding display is essential before learning more advanced CSS layout techniques because many common layout problems are actually caused by using the wrong display mode.

How Do You Use the display Property?

The basic syntax is:

</pre>

        <p class="mt-5">
          The value determines the layout behavior of the element.
        </p>

        <pre class="mt-4 bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.card {
  display: block;
}

.navigation {
  display: flex;
}

.gallery {
  display: grid;
}

What Are the Most Common CSS display Values?

Value Purpose
block Creates a block-level box.
inline Places the element within the inline flow.
inline-block Combines inline flow with a block-like box.
flex Creates a flex container.
grid Creates a grid container.
none Removes the element from layout.
flow-root Creates a new block formatting context.

What Does display: block Do?

display: block makes the element participate as a block-level box in normal flow.

Block-level elements normally begin on a new line and, when their inline size is auto, can stretch to fill the available inline space within their containing block.

</pre>

        <p class="mt-5">
          Common elements such as <code class="text-blue-300">div</code>,
          <code class="text-blue-300">section</code>, and
          <code class="text-blue-300">p</code> have block-level behavior by default in typical
          browser styles.
        </p>

        <div class="rounded-xl border border-slate-700 bg-slate-900 p-5 mt-6">
          <div class="space-y-2">
            <div class="rounded-lg border border-slate-600 p-3">
              Block element
            </div>
            <div class="rounded-lg border border-slate-600 p-3">
              Next block element
            </div>
          </div>
        </div>
      </section>

      <!-- Inline -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Does display: inline Do?
        </h2>

        <p class="mb-4">
          <code class="text-blue-300">display: inline</code> makes an element participate in the
          inline formatting context, allowing it to flow alongside surrounding inline content.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.label {
  display: inline;
}

Inline elements generally do not behave like standalone block boxes. In particular, setting a width or height on an ordinary inline box does not work in the same way it does for a block-level or inline-block box.

Elements such as span and a commonly have inline behavior by default.

<p>
  Learn <span class="highlight">CSS display</span>
  with practical examples.
</p>

<style>
.highlight {
  display: inline;
  font-weight: 700;
}
</style>

What Does display: inline-block Do?

display: inline-block allows an element to participate in inline flow while behaving more like a block-level box for sizing and box-model purposes.

This means multiple elements can sit on the same line while still accepting explicit width, height, padding, and borders in the expected box-model manner.

</pre>

        <div class="mt-6 flex flex-wrap gap-3">
          <div class="inline-block rounded-lg border border-slate-600 px-5 py-3 text-center">
            Button One
          </div>

          <div class="inline-block rounded-lg border border-slate-600 px-5 py-3 text-center">
            Button Two
          </div>

          <div class="inline-block rounded-lg border border-slate-600 px-5 py-3 text-center">
            Button Three
          </div>
        </div>

        <p class="mt-5">
          Although Flexbox and Grid are preferred for many modern layouts, inline-block remains
          useful for simple inline components and legacy layout patterns.
        </p>
      </section>

      <!-- Flex -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Does display: flex Do?
        </h2>

        <p class="mb-4">
          <code class="text-blue-300">display: flex</code> turns an element into a
          <strong class="text-white">flex container</strong>. Its direct children become flex items.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

Flexbox is primarily used for one-dimensional layouts where items are arranged along a row or column.

Navigation

Align links and actions in a row.

Toolbar

Position controls with consistent spacing.

Component Alignment

Center or distribute internal content.

What Does display: grid Do?

display: grid turns an element into a grid container. Its direct children become grid items.

</pre>

        <p class="mt-5">
          Grid is designed for two-dimensional layouts where rows and columns are both important.
        </p>

        <div class="mt-6 grid grid-cols-3 gap-3">
          <div class="rounded-lg border border-slate-600 p-4 text-center">1</div>
          <div class="rounded-lg border border-slate-600 p-4 text-center">2</div>
          <div class="rounded-lg border border-slate-600 p-4 text-center">3</div>
          <div class="rounded-lg border border-slate-600 p-4 text-center">4</div>
          <div class="rounded-lg border border-slate-600 p-4 text-center">5</div>
          <div class="rounded-lg border border-slate-600 p-4 text-center">6</div>
        </div>
      </section>

      <!-- None -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Does display: none Do?
        </h2>

        <p class="mb-4">
          <code class="text-blue-300">display: none</code> removes the element from the layout.
          It does not occupy space as a rendered box.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.mobile-menu {
  display: none;
}

It is commonly used with responsive layouts or interactive interfaces where an element should not participate in layout while hidden.

</pre>

        <p class="mt-5">
          This is different from merely making an element transparent or visually hiding it with
          other techniques. <code class="text-blue-300">display: none</code> changes whether the
          element generates a box in the layout.
        </p>
      </section>

      <!-- Flow Root -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Does display: flow-root Do?
        </h2>

        <p class="mb-4">
          <code class="text-blue-300">display: flow-root</code> creates a new
          <strong class="text-white">block formatting context</strong> for the element.
          This can be useful when you need the container to establish an independent formatting
          context without relying on older clearfix techniques.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.container {
  display: flow-root;
}

One practical use is containing floated descendants so that the parent establishes its own formatting context.

</pre>
      </section>

      <!-- Inline Flex -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Is the Difference Between display: flex and display: inline-flex?
        </h2>

        <p class="mb-4">
          Both values create a Flexbox formatting context for the element's contents, but they
          differ in how the outer element participates in surrounding layout.
        </p>

        <div class="grid md:grid-cols-2 gap-6">

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-3">
              display: flex
            </h3>

            <p class="text-sm">
              The element behaves as a block-level flex container in surrounding layout.
            </p>

            <pre class="mt-4 bg-slate-950 border border-slate-700 rounded-xl p-4 overflow-x-auto text-sm"><code:.box {
  display: flex;
}

display: inline-flex

The element participates in surrounding inline layout while its contents use Flexbox.

</pre>
          </div>

        </div>
      </section>

      <!-- Inline Grid -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Is the Difference Between display: grid and display: inline-grid?
        </h2>

        <p class="mb-4">
          The same outer-layout distinction applies to Grid.
          <code class="text-blue-300">grid</code> creates a block-level grid container, while
          <code class="text-blue-300">inline-grid</code> creates a grid container that participates
          in the surrounding inline formatting context.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.panel {
  display: inline-grid;
  grid-template-columns: repeat(2, auto);
  gap: 0.5rem;
}

Can display Create Table-Like Layouts?

CSS provides table-related display values such as table, table-row, and table-cell.

These values can reproduce certain table formatting behaviors, but semantic HTML elements such as table, tr, and td are generally more appropriate when the content is actually tabular data.

</pre>

        <p class="mt-5">
          CSS display values should not be used as a substitute for semantic HTML when the meaning
          of the content matters.
        </p>
      </section>

      <!-- Layout Behavior -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          How Does display Affect Element Width and Height?
        </h2>

        <p class="mb-4">
          The display mode has a major effect on how width, height, and surrounding content behave.
        </p>

        <div class="overflow-x-auto rounded-xl border border-slate-700">
          <table class="w-full text-left text-sm">
            <thead class="bg-slate-800 text-white">
              <tr>
                <th class="px-4 py-3">Display</th>
                <th class="px-4 py-3">Typical Behavior</th>
              </tr>
            </thead>

            <tbody class="divide-y divide-slate-700 bg-slate-900">
              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">block</td>
                <td class="px-4 py-3">Starts a new block-level box and can accept width and height.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">inline</td>
                <td class="px-4 py-3">Participates in inline flow; width and height do not work like a block box.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">inline-block</td>
                <td class="px-4 py-3">Participates inline while supporting box sizing more like a block.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">flex</td>
                <td class="px-4 py-3">Creates a flexible formatting context for direct children.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">grid</td>
                <td class="px-4 py-3">Creates a grid formatting context for direct children.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">none</td>
                <td class="px-4 py-3">The element does not generate a box in the layout.</td>
              </tr>
            </tbody>
          </table>
        </div>
      </section>

      <!-- Parent Child -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          How Does display Affect Child Elements?
        </h2>

        <p class="mb-4">
          Some display values do more than change the outer element. They also establish a specific
          layout context for the element's children.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.container {
  display: flex;
}

In this case, the direct children become flex items.

</pre>

        <p class="mt-5">
          Here, the direct children become grid items.
        </p>

        <p class="mt-4">
          This is why changing the parent's <code class="text-blue-300">display</code> value can
          have a large effect on the layout of multiple elements at once.
        </p>
      </section>

      <!-- Block vs Inline -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Is the Difference Between Block, Inline, and Inline-Block?
        </h2>

        <div class="overflow-x-auto rounded-xl border border-slate-700">
          <table class="w-full text-left text-sm">
            <thead class="bg-slate-800 text-white">
              <tr>
                <th class="px-4 py-3">Feature</th>
                <th class="px-4 py-3">block</th>
                <th class="px-4 py-3">inline</th>
                <th class="px-4 py-3">inline-block</th>
              </tr>
            </thead>

            <tbody class="divide-y divide-slate-700 bg-slate-900">
              <tr>
                <td class="px-4 py-3 font-semibold text-white">New line</td>
                <td class="px-4 py-3">Yes</td>
                <td class="px-4 py-3">No</td>
                <td class="px-4 py-3">No</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-semibold text-white">Width</td>
                <td class="px-4 py-3">Supported</td>
                <td class="px-4 py-3">Not applied like a block box</td>
                <td class="px-4 py-3">Supported</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-semibold text-white">Height</td>
                <td class="px-4 py-3">Supported</td>
                <td class="px-4 py-3">Not applied like a block box</td>
                <td class="px-4 py-3">Supported</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-semibold text-white">Inline flow</td>
                <td class="px-4 py-3">No</td>
                <td class="px-4 py-3">Yes</td>
                <td class="px-4 py-3">Yes</td>
              </tr>
            </tbody>
          </table>
        </div>
      </section>

      <!-- Responsive -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          How Is display Used for Responsive Design?
        </h2>

        <p class="mb-4">
          One of the most common uses of <code class="text-blue-300">display</code> is changing
          layout behavior at different viewport sizes.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code:.navigation {
  display: flex;
}

.mobile-toggle {
  display: none;
}

@media (max-width: 768px) {
  .navigation {
    display: none;
  }

  .mobile-toggle {
    display: flex;
  }
}

This example switches between a desktop navigation and a mobile control based on the viewport width.

The same principle can be applied to columns, sidebars, optional panels, filters, toolbars, and other interface elements.

What Is the Difference Between display: none and visibility: hidden?

These properties are often confused, but they have different layout behavior.

display: none

The element does not generate a box in the layout.

</pre>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="text-lg font-semibold text-white mb-3">
              visibility: hidden
            </h3>

            <p class="mb-4">
              The element remains in the layout but is visually hidden.
            </p>

            <pre class="bg-slate-950 border border-slate-700 rounded-xl p-4 overflow-x-auto text-sm"><code.hidden {
  visibility: hidden;
}

Choose the property based on whether the element should continue participating in the layout.

What Does display: contents Do?

display: contents causes the element itself not to generate its own principal box while its children can participate in the surrounding layout as though the wrapper were not generating a box.

</pre>

        <p class="mt-5">
          This can occasionally be useful when an extra wrapper should not introduce its own layout
          box, but it should be used thoughtfully because the wrapper's box is not participating
          in layout and this can affect styling and other box-related behavior.
        </p>
      </section>

      <!-- Practical Example -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          How Can display Be Used to Build a Responsive Header?
        </h2>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code><header class="header">
  <a href="/" class="logo">IgKnight</a>

  <nav class="desktop-nav">
    <a href="/docs">Documentation</a>
    <a href="/practice">Practice</a>
    <a href="/compiler">Compiler</a>
  </nav>

  <button class="mobile-menu">
    Menu
  </button>
</header>
</pre>

        <p class="mt-5">
          Here the header itself uses Flexbox, while the visibility of the navigation and mobile
          control is changed using <code class="text-blue-300">display</code> inside a media query.
        </p>
      </section>

      <!-- Common Problems -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          Why Is My CSS display Property Not Working?
        </h2>

        <div class="space-y-5">

          <div class="rounded-xl border border-red-900/50 bg-red-950/20 p-5">
            <h3 class="text-lg font-semibold text-white mb-2">
              The selector is not targeting the element
            </h3>

            <p>
              Check the selector, stylesheet loading, specificity, and whether another rule later
              in the cascade is overriding the display value.
            </p>
          </div>

          <div class="rounded-xl border border-red-900/50 bg-red-950/20 p-5">
            <h3 class="text-lg font-semibold text-white mb-2">
              A child is not behaving as expected
            </h3>

            <p>
              Remember that <code class="text-blue-300">display: flex</code> and
              <code class="text-blue-300">display: grid</code> change the formatting context
              used by the direct children.
            </p>
          </div>

          <div class="rounded-xl border border-red-900/50 bg-red-950/20 p-5">
            <h3 class="text-lg font-semibold text-white mb-2">
              Width does not seem to work
            </h3>

            <p>
              Check whether the element is using an inline display mode. An ordinary inline box
              does not respond to width and height the same way a block or inline-block box does.
            </p>
          </div>

          <div class="rounded-xl border border-red-900/50 bg-red-950/20 p-5">
            <h3 class="text-lg font-semibold text-white mb-2">
              display: none appears to do more than expected
            </h3>

            <p>
              That is expected. <code class="text-blue-300">display: none</code> removes the element
              from layout rather than simply making it transparent.
            </p>
          </div>

          <div class="rounded-xl border border-red-900/50 bg-red-950/20 p-5">
            <h3 class="text-lg font-semibold text-white mb-2">
              A framework utility is overriding the value
            </h3>

            <p>
              Utility CSS frameworks can generate competing declarations. Inspect the computed
              styles in browser DevTools to determine which declaration is winning.
            </p>
          </div>

        </div>
      </section>

      <!-- Choosing Display -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          How Do You Choose the Right display Value?
        </h2>

        <div class="grid md:grid-cols-2 gap-5">

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Need normal block layout?
            </h3>
            <p>
              Use <code class="text-blue-300">display: block</code>.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Need inline text-like behavior?
            </h3>
            <p>
              Use <code class="text-blue-300">display: inline</code>.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Need an inline-sized component with box dimensions?
            </h3>
            <p>
              Consider <code class="text-blue-300">display: inline-block</code>.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Need one-dimensional alignment?
            </h3>
            <p>
              Use <code class="text-blue-300">display: flex</code>.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Need rows and columns?
            </h3>
            <p>
              Use <code class="text-blue-300">display: grid</code>.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Need to remove the element from layout?
            </h3>
            <p>
              Use <code class="text-blue-300">display: none</code>.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5 md:col-span-2">
            <h3 class="font-semibold text-white mb-2">
              Need an independent block formatting context?
            </h3>
            <p>
              Consider <code class="text-blue-300">display: flow-root</code> when that behavior
              matches the layout problem.
            </p>
          </div>

        </div>
      </section>

      <!-- Browser DevTools -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          How Can DevTools Help Debug display Problems?
        </h2>

        <p class="mb-4">
          Browser DevTools are especially useful when a display declaration does not produce
          the expected result.
        </p>

        <div class="space-y-4">
          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white">Inspect the element</h3>
            <p class="mt-2">
              Confirm that the expected element is actually selected.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white">Check computed styles</h3>
            <p class="mt-2">
              Find the final computed <code class="text-blue-300">display</code> value.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white">Look for overridden declarations</h3>
            <p class="mt-2">
              Another selector, media query, utility class, or stylesheet may be winning in the cascade.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white">Inspect the layout</h3>
            <p class="mt-2">
              Flex and Grid debugging tools can help visualize the formatting context created by the container.
            </p>
          </div>
        </div>
      </section>

      <!-- Best Practices -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Are the Best Practices for Using CSS display?
        </h2>

        <div class="grid md:grid-cols-2 gap-5">

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Use semantic HTML first
            </h3>
            <p>
              HTML elements should describe the content and structure. Use CSS display to control presentation.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Use Flexbox for one-dimensional layouts
            </h3>
            <p>
              It is usually clearer than manually positioning a row of related items.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Use Grid for two-dimensional layouts
            </h3>
            <p>
              Grid is a natural fit when rows and columns both matter.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Do not hide content accidentally
            </h3>
            <p>
              Use <code class="text-blue-300">display: none</code> only when removing the element from layout is intended.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Keep responsive rules understandable
            </h3>
            <p>
              Use media queries to change display behavior when the layout genuinely needs a different structure.
            </p>
          </div>

          <div class="rounded-xl border border-slate-700 bg-slate-900 p-5">
            <h3 class="font-semibold text-white mb-2">
              Debug the computed value
            </h3>
            <p>
              When display behaves unexpectedly, inspect the cascade instead of guessing.
            </p>
          </div>

        </div>
      </section>

      <!-- Quick Reference -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          CSS display Values at a Glance
        </h2>

        <div class="overflow-x-auto rounded-xl border border-slate-700">
          <table class="w-full text-left text-sm">
            <thead class="bg-slate-800 text-white">
              <tr>
                <th class="px-4 py-3">Value</th>
                <th class="px-4 py-3">Best Used For</th>
              </tr>
            </thead>

            <tbody class="divide-y divide-slate-700 bg-slate-900">
              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">block</td>
                <td class="px-4 py-3">Normal block-level sections and containers.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">inline</td>
                <td class="px-4 py-3">Text-level and inline content.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">inline-block</td>
                <td class="px-4 py-3">Inline components that need box dimensions.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">flex</td>
                <td class="px-4 py-3">One-dimensional component layouts.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">inline-flex</td>
                <td class="px-4 py-3">Inline elements whose contents use Flexbox.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">grid</td>
                <td class="px-4 py-3">Two-dimensional row and column layouts.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">inline-grid</td>
                <td class="px-4 py-3">Inline elements whose contents use Grid.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">flow-root</td>
                <td class="px-4 py-3">A new block formatting context.</td>
              </tr>

              <tr>
                <td class="px-4 py-3 font-mono text-blue-300">none</td>
                <td class="px-4 py-3">Removing an element from layout.</td>
              </tr>
            </tbody>
          </table>
        </div>
      </section>

      <!-- Final Example -->
      <section>
        <h2 class="text-2xl md:text-3xl font-bold text-white mb-4">
          What Is a Practical CSS display Example?
        </h2>

        <p class="mb-5">
          The following example combines several display modes in a small responsive interface.
        </p>

        <pre class="bg-slate-950 border border-slate-700 rounded-xl p-5 overflow-x-auto text-sm"><code><div class="page">

  <header class="header">
    <a href="/" class="logo">IgKnight</a>

    <nav class="navigation">
      <a href="/docs">Documentation</a>
      <a href="/practice">Practice</a>
      <a href="/compiler">Compiler</a>
    </nav>

    <button class="menu">
      Menu
    </button>
  </header>

  <main class="content">
    <section class="cards">
      <article class="card">Documentation</article>
      <article class="card">Practice</article>
      <article class="card">Compiler</article>
    </section>
  </main>

</div>


        

This example shows how different display modes can be combined rather than forcing the entire page to use a single layout technique.

Key Takeaways

  • The display property controls how an element participates in layout and how its contents are laid out.
  • display: block creates a block-level box.
  • display: inline keeps the element in inline flow.
  • display: inline-block combines inline participation with block-like box sizing.
  • display: flex creates a Flexbox container.
  • display: grid creates a Grid container.
  • display: none removes the element from layout.
  • display: flow-root establishes a new block formatting context.
  • inline-flex and inline-grid combine inline outer behavior with Flexbox or Grid for the contents.
  • Choosing the correct display mode makes CSS layouts simpler, more predictable, and easier to maintain.

Code Examples

Block and Inline Elements

css
.section {
  display: block;
}

.highlight {
  display: inline;
}

.button {
  display: inline-block;
  width: 140px;
  padding: 0.75rem 1rem;
}
    

Flexbox Layout

css
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
    

Responsive Display

css
.desktop-nav {
  display: flex;
}

.mobile-menu {
  display: none;
}

@media (max-width: 768px) {
  .desktop-nav {
    display: none;
  }

  .mobile-menu {
    display: inline-flex;
  }
}
    

Grid and Flexbox Together

html
<main class="page">
  <header class="header">
    <h1>Dashboard</h1>

    <div class="actions">
      <button>Refresh</button>
      <button>Profile</button>
    </div>
  </header>

  <section class="cards">
    <article class="card">Users</article>
    <article class="card">Projects</article>
    <article class="card">Revenue</article>
  </section>
</main>

<style>
.page {
  display: block;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.actions {
  display: flex;
  gap: 0.75rem;
}

.cards {
  display: grid;
  grid-template-columns:
    repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.card {
  display: block;
  padding: 1.5rem;
}
</style>
    

Pro Tip

When a CSS layout is behaving strangely, inspect the computed display value first. Then determine whether the element should participate in normal flow, inline flow, Flexbox, Grid, or no layout at all. Many spacing and alignment problems become much easier to solve once the correct formatting context is identified.

More CSS lessons

🎨 IgKnight Docs

Master HTML, CSS, JS, Python, .NET and more with easy-to-follow lessons and practical code examples.

© 2025 IgKnight Learning Platform. All rights reserved.