Questions
12 of 49
1What is the display property in CSS used for?
2What is the default display value for <div>, <span>, <p>, and <a> tags?
3What is the difference between display: block and display: inline?
4How does display: inline-block behave?
5What happens when you set display: none on an element?
6How is display: none different from visibility: hidden?
7Can display: none affect layout reflow or accessibility?
8What’s the effect of display: block on inline elements like <span>?
9What’s the difference between display: table and actual HTML <table> elements?
10How do replaced elements (like <img> or <input>) behave with different display values?
11How is display: flex different from display: block?
12What is the difference between display: grid and display: flex?
13What happens if you apply display: inline-flex to a container?
14What is the difference between display: contents and display: none?
15What is display: list-item, and when is it used?
16How does display: run-in work, and why is it rarely used?
17What’s the difference between display: inline-grid and display: grid?
18How can you make an element behave like both inline and block elements?
19What happens to child elements when the parent has display: contents?
20How does the display property affect box model calculations?
21How can you change a block-level element to behave like an inline element without changing its tag?
22How do you center elements using display: flex or display: grid?
23How can you hide elements but keep their layout space?
24What happens to child elements when their parent has display: none?
25How can display: contents help improve semantic markup but hurt accessibility?
26What happens if you set display: flex on the <body> tag?
27How do you use display to build responsive layouts?
28What is the difference between using display and position to arrange elements?
29How can you visually hide an element but keep it accessible for screen readers?
30How does display affect stacking and z-index behavior?
31Does display: none remove an element from the DOM?
32Can an element with display: none trigger CSS transitions or animations?
33How does display interact with CSS pseudo-elements (::before, ::after)?
34What is the difference between visibility: collapse and display: none in table elements?
35How can you make text and icons align properly using display values?
36How do block formatting contexts relate to display types?
37What happens if you apply display: table to a flex container?
38How does display behave differently for replaced vs. non-replaced elements?
39Can display be animated using CSS transitions?
40How does display affect the accessibility tree and ARIA roles?
41How can you make a <li> element appear horizontally instead of vertically?
42How do you create a two-column layout without using float or position, using only display?
43How do you make an image and text sit side by side neatly?
44How would you make a navigation menu horizontally aligned using display?
45How can you make all elements behave as border-box and block-level by default?
46How would you use display: flex to make a footer stick to the bottom?
47How can display: grid simplify responsive design compared to floats?
48When would you prefer display: inline-flex over display: flex?
49How can you use display: contents to remove extra wrappers in semantic HTML structures? How can incorrect use of display lead to accessibility or SEO problems?
12 / 49

What is the difference between display: grid and display: flex?

Difference Between display: grid and display: flex in CSS

display: flex and display: grid are both CSS layout models, but they serve different purposes. Flexbox is designed for one-dimensional layouts (row or column), while Grid is designed for two-dimensional layouts (rows and columns simultaneously).

Key Differences
  1. 1

    flex arranges child elements along a single axis (horizontal or vertical), while grid allows layout along both rows and columns.

  2. 2

    flex is ideal for distributing space and aligning items in a single row or column, whereas grid provides precise control over both dimensions of the layout.

  3. 3

    Flex items can wrap to multiple lines with flex-wrap, but Grid defines explicit row and column structures.

  4. 4

    Grid supports features like named areas, spanning multiple rows/columns, and gap controls (row-gap, column-gap) that Flexbox doesn’t provide natively.

  5. 5

    Both models support alignment, but Grid allows aligning items along two axes independently, whereas Flexbox primarily aligns along the main and cross axis.

Example: Flex vs Grid

In this example, the Flex container arranges items in a single row with spacing between them. The Grid container arranges items in a two-column layout with precise control over columns and gaps.

Best Practices
  1. 1

    Use Flexbox for simple one-dimensional layouts, like nav bars or horizontal lists.

  2. 2

    Use Grid for complex two-dimensional layouts where both rows and columns need precise control.

  3. 3

    Combine Flex and Grid strategically for responsive, modern layouts.

Difficulty: 5/10
Topics: layout, responsive design, CSS Grid vs Flexbox

Scenario Questions

0-2 years experience
  1. 1

    You need to create a simple navigation bar with items spaced evenly across the width. Would you use Flexbox or Grid, and how would you write the CSS?

  2. 2

    If you set a container to display: grid but only define one column, what layout behavior do you observe compared to display: flex?

2-5 years experience
  1. 1

    While building a product listing page, the layout breaks on mobile after adding a new filter sidebar. How would you debug whether Flexbox or Grid is causing the issue?

  2. 2

    You have a card component that needs a header, image, body, and footer arranged in a column, but the body should stretch to fill remaining space. Which layout system would you pick and why?

5-8 years experience
  1. 1

    Our design system currently uses Flexbox for most components, but a new dashboard requires a complex matrix layout with overlapping items. How would you approach refactoring the relevant components, and what trade‑offs would you consider?

  2. 2

    Explain how you would ensure consistent alignment and spacing when mixing Grid containers inside Flexbox parents across a large application.

8+ years experience
  1. 1

    We plan to migrate a legacy codebase that heavily relies on Flexbox to a Grid‑first approach for better maintainability. What strategy would you propose for a phased rollout, and how would you mitigate regression risk?

  2. 2

    At an organization‑wide level, how would you set guidelines for when teams should prefer Grid over Flexbox, considering performance, developer experience, and future scalability?

Follow-up Questions

  • How would you decide which layout method to use for a card component that needs both horizontal and vertical alignment?
  • Can you describe a situation where mixing Grid and Flexbox in the same component makes sense?
  • What are the browser support considerations when adopting Grid in an existing codebase?