Questions
48 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?
48 / 49

When would you prefer display: inline-flex over display: flex?

Choosing Between Flex and Inline-Flex in CSS

Both flex and inline-flex create a flex container, allowing child elements to be laid out using the Flexbox model. The key difference is how the container itself behaves in the surrounding layout.

Differences
  1. 1

    display: flex – The container behaves as a block-level element, occupying the full width available and stacking vertically with other block elements.

  2. 2

    display: inline-flex – The container behaves as an inline-level element, flowing alongside text or other inline elements while still laying out its children as a flex container.

Example: Flex vs Inline-Flex

In this example, the block flex container takes up the full width, while the inline-flex container sits inline with surrounding text.

When to Use Inline-Flex
  1. 1

    When you want the flex container to sit inline with text or other inline elements, such as icon-label pairs.

  2. 2

    For small UI components like buttons, badges, or input groups that should flow inline with surrounding content.

  3. 3

    When you need the layout benefits of flex for children but don’t want the container to behave as a block element.

When to Use Flex
  1. 1

    When the container should occupy the full width and stack like a block element.

  2. 2

    For main layout sections, sidebars, or full-width navigation bars.

  3. 3

    When vertical spacing relative to other block elements matters.

Difficulty: 4/10
Topics: flexbox, inline formatting, responsive layout

Scenario Questions

0-2 years experience
  1. 1

    You need three icons to appear next to a paragraph of text without breaking the line. How would you style them, and why might you choose display:inline‑flex over display:flex?

  2. 2

    If you apply display:flex to a <span> inside a paragraph, what happens to the layout? How would you adjust it to keep the span inline while still using flexbox for its children?

  3. 3

    You have a button that contains an SVG icon and a label. Which display property would you pick to keep the button inline with surrounding text and why?

2-5 years experience
  1. 1

    While building a navigation bar, the flex container forces the bar onto a new line on small screens. How would you refactor it with inline‑flex, and what trade‑offs would you consider?

  2. 2

    A teammate reports that a component using display:flex is breaking the surrounding text flow in a CMS page. Walk me through how you’d debug the issue and decide whether to switch to inline‑flex.

  3. 3

    You need a reusable card component that may be placed inside a paragraph of rich text. Explain how you’d decide between flex and inline‑flex for its root element, considering layout and reusability.

5-8 years experience
  1. 1

    Our design system includes a button‑group component that sometimes appears inside inline text and sometimes as a toolbar. How would you design its CSS to handle both scenarios, and when would you expose a prop to toggle between flex and inline‑flex?

  2. 2

    During a performance audit we found many inline‑flex components cause extra reflow when the page width changes. Explain why this happens and how you’d mitigate the impact at a component‑library level.

  3. 3

    You’re leading a migration from a legacy float‑based layout to flexbox. Some components need to stay inline with surrounding content. Describe your strategy to replace those with inline‑flex while ensuring backward compatibility.

8+ years experience
  1. 1

    Our organization is consolidating multiple UI libraries into a single design system. Some libraries use display:flex for components that should be inline, causing inconsistent text flow. How would you drive a cross‑team initiative to standardize inline‑flex usage, and what migration plan would you propose?

  2. 2

    Consider a large‑scale content platform where editors can embed arbitrary components within articles. Discuss the architectural implications of choosing inline‑flex versus flex for the base component wrapper, especially regarding SEO, accessibility, and rendering performance.

  3. 3

    You need to future‑proof the layout engine of a web‑based IDE that renders code editors, toolbars, and inline annotations. How would you decide when to use inline‑flex at the system level, and what guidelines would you set for downstream teams?

Follow-up Questions

  • What effect does inline‑flex have on the element’s surrounding siblings?
  • How does vertical alignment differ between flex and inline‑flex?
  • Can you describe any pitfalls when using inline‑flex in a responsive design?