Questions
27 of 51
1What is Flexbox in CSS?
2What problem does Flexbox solve compared to traditional layouts like float or inline-block?
3How do you create a flex container?
4What are the main and cross axes in Flexbox?
5What does the display: flex property do?
6What is the difference between display: flex and display: inline-flex?
7What are flex items?
8How do you change the direction of items in a flex container?
9What does flex-direction: row do?
10What does flex-direction: column do?
11What is the purpose of the justify-content property?
12What does the align-items property control?
13What are the possible values of align-content?
14What is the difference between align-items and align-content?
15What is the use of the flex-wrap property?
16How can you make flex items wrap onto multiple lines?
17What does the flex-flow shorthand property do?
18How does the order property affect flex items?
19How does the align-self property work?
20How do you vertically center content using Flexbox?
21What does the flex shorthand property represent?
22What are the three components of the flex shorthand property?
23What is the default value of the flex property?
24How do flex-grow, flex-shrink, and flex-basis work individually?
25What is the difference between flex: 1 and flex: auto?
26What is the difference between flex: 1 and flex: auto?
27What is the purpose of the gap property in Flexbox?
28How does Flexbox handle overflowing content?
29What’s the difference between justify-content: space-around and space-between?
30How does Flexbox handle fixed and flexible widths together?
31Can Flexbox be nested?
32How is Flexbox different from CSS Grid?
33When would you use Flexbox instead of Grid?
34Can you use Flexbox and Grid together in the same layout?
35How does Flexbox differ from traditional float-based layouts?
36Does Flexbox affect the box model or positioning of elements?
37How does Flexbox handle min-width and max-width constraints?
38How do flex items align when the container has align-items: stretch?
39What is the difference between flex: 0 1 auto and flex: 1 0 auto?
40How does flex-basis differ from width?
41How do you prevent a flex item from shrinking?
42How would you create a horizontal navigation bar using Flexbox?
43How do you center a div both horizontally and vertically using Flexbox?
44How can you make a responsive layout using Flexbox?
45How can you make one flex item take up the remaining space in a container?
46How do you create equal-height columns using Flexbox?
47How can you align the last flex item to the right side of the container?
48How can you reorder items visually using Flexbox without changing the HTML structure?
49How can you make items stack vertically on mobile and horizontally on desktop using Flexbox?
50How do you prevent an element from wrapping in a flex container?
51How can you align items to the bottom of a container using Flexbox?
27 / 51

What is the purpose of the gap property in Flexbox?

Understanding the gap Property in Flexbox

The gap property in Flexbox is used to define consistent spacing between flex items without the need for margins on individual items. It simplifies layout spacing and avoids margin collapse issues.

Key Points
  1. 1

    gap: <length>; sets the spacing between all flex items along the main and cross axes.

  2. 2

    Supports row-gap and column-gap for specifying different spacing in rows and columns.

  3. 3

    Works with both flex and grid containers.

Example: Using gap in Flexbox

In this example, gap: 20px ensures that all items inside the flex container have a uniform 20px spacing between them without adding individual margins.

Difficulty: 3/10
Topics: flexbox layout, spacing control, responsive design

Scenario Questions

0-2 years experience
  1. 1

    You're building a card grid with 4 items in a row, and they're too close together. How would you use gap to add even spacing between them without messing up the alignment?

  2. 2

    If you set gap: 20px on a flex container but the items still look unevenly spaced, what’s the most likely mistake someone made?

  3. 3

    You have a flex row with three buttons and want 10px between them. How do you write the CSS to make that happen?

2-5 years experience
  1. 1

    A designer says the spacing between cards in our mobile feed looks off when the screen shrinks — the gap stays fixed but the cards wrap. How would you debug and fix this?

  2. 2

    Our team uses margin-right: 16px on flex items to create spacing, but it causes overflow on the last item. Why is gap a better solution here, and what edge case might you still need to handle?

  3. 3

    A flex layout with gap works fine in Chrome but breaks in Safari. What could be the issue, and how would you verify and resolve it?

5-8 years experience
  1. 1

    You're designing a dynamic dashboard with variable numbers of widgets in a flex container. How would you use gap to ensure consistent spacing across breakpoints while avoiding layout shifts on resize?

  2. 2

    In a high-performance UI, we’re using gap instead of margins for spacing. What performance implications should you consider when animating or reflowing hundreds of flex items with gap?

  3. 3

    A legacy component uses padding on the container to simulate spacing. You want to migrate to gap. What compatibility, accessibility, or layout stability risks should you evaluate before rolling it out?

8+ years experience
  1. 1

    We’re standardizing our design system across 12 product teams. Should we enforce gap as the sole spacing mechanism for flex containers? What tradeoffs do you weigh between consistency, browser support, and legacy code debt?

  2. 2

    Our CSS architecture uses a utility-first framework. How would you design a scalable, maintainable spacing system that integrates gap with other layout primitives without creating combinatorial explosion?

  3. 3

    A major browser is deprecating margin-based spacing patterns. How would you lead a cross-team migration from legacy flex spacing to gap, including testing strategy, fallbacks, and developer education?

Follow-up Questions

  • What happens if you use gap on a non-flex container?
  • How does gap behave when flex items wrap?
  • Can you combine gap with margin on flex items? What might go wrong?