QA
Beginner LevelCSS & Modern Layouts

What are the differences between display: block, inline, inline-block, flex, and grid?

❓ Interview Prompt: Compare the five main CSS display values and when to use each one.

The display property defines how an element generates boxes and participates in layout:

| Display Value | New Line? | Width/Height? | Use Case |

| :--- | :--- | :--- | :--- |

| block | Yes, starts on new line | Accepts width/height | Divs, paragraphs, sections |

| inline | No, flows with text | Ignores width/height | Spans, links, emphasis |

| inline-block | No, flows with text | Accepts width/height | Buttons, badges, tags |

| flex | Yes (container) | Children flex | Navbars, card rows, toolbars |

| grid | Yes (container) | Children placed in grid cells | Page layouts, dashboards, galleries |

Code Implementation Example

css
/* Navbar using Flexbox */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

/* Dashboard using Grid */
.dashboard {
  display: grid;
  grid-template-columns: 250px 1fr;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}
💡Flexbox for 1D navigation layout vs Grid for 2D dashboard layout.
🎯 Interview Key Takeaway

Use flex for one-dimensional alignment (row or column) and grid for two-dimensional page layouts.

#Display#Flexbox#Grid#Layout#Beginner
Back to all CSS & Modern Layouts Questions→

More CSS & Modern Layouts Interview Questions

Beginner LevelCSS & Modern Layouts

What is the CSS Box Model and how do content, padding, border, and margin interact?

Beginner LevelCSS & Modern Layouts

How does CSS specificity and the cascade determine which styles are applied?

Beginner LevelCSS & Modern Layouts

How does CSS Flexbox work and what are its key container and item properties?