Questions
5 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?
05 / 51

What does the display: flex property do?

Understanding display: flex in CSS

display: flex transforms an element into a flex container, enabling the Flexbox layout model. This allows its direct children (flex items) to be aligned and distributed along both the main and cross axes with ease.

Key Points
  1. 1

    display: flex creates a block-level flex container; display: inline-flex creates an inline-level flex container.

  2. 2

    Direct child elements become flex items, which can grow, shrink, and align automatically within the container.

  3. 3

    Flexbox provides one-dimensional layout control (row or column) along the main axis.

  4. 4

    It simplifies spacing, alignment, and responsiveness compared to floats or inline-block layouts.

  5. 5

    Flex properties like justify-content, align-items, and flex-wrap control the layout of flex items inside the container.

Example: Basic Flex Container

In this example, the .container becomes a flex container, arranging its children .item along the main axis with equal spacing and centering them along the cross axis.

Best Practices
  1. 1

    Use display: flex for one-dimensional layouts where items need to be aligned in a row or column.

  2. 2

    Combine with flex-wrap for responsive designs where items may need to wrap onto multiple lines.

  3. 3

    Understand the main axis vs cross axis to apply proper alignment.

  4. 4

    Test across different browsers and screen sizes to ensure consistent layout behavior.

Difficulty: 3/10
Topics: flex container, flex items, alignment

Scenario Questions

0-2 years experience
  1. 1

    How would you center a button and a text label horizontally inside a header using flexbox?

  2. 2

    What happens if you set display: flex on a div with three child divs but don’t specify any flex properties?

  3. 3

    If you have two flex items and one has flex: 2 while the other has flex: 1, how will they divide the available space?

2-5 years experience
  1. 1

    A responsive card grid breaks on mobile — the items overflow the container even though you set flex-wrap: wrap. What could be causing this and how would you debug it?

  2. 2

    You’re building a navigation bar that should collapse into a vertical stack on small screens, but the items are still wrapping oddly. What flex properties might you be missing or misusing?

  3. 3

    Why might a flex item with text content appear truncated on some browsers even though it has flex: 1 and no explicit width?

5-8 years experience
  1. 1

    You’re designing a dynamic dashboard with resizable panels that use flexbox. How would you handle performance when users resize multiple panels simultaneously, and what edge cases might cause layout thrashing?

  2. 2

    How would you structure a complex form layout with nested flex containers that needs to support RTL, screen readers, and dynamic field additions without breaking accessibility or responsiveness?

  3. 3

    A legacy component uses flexbox for a list of cards, but it’s causing layout shifts during lazy loading. What’s the root cause and how would you fix it without rewriting the entire component?

8+ years experience
  1. 1

    You’re leading a migration from CSS Grid to Flexbox for a large-scale UI library used across 50+ products. What tradeoffs do you weigh in terms of maintainability, browser support, and developer ergonomics?

  2. 2

    How would you design a cross-team CSS architecture standard for flexbox usage that prevents layout bugs when teams integrate components with conflicting flex behaviors?

  3. 3

    A legacy app uses flexbox for layout but has inconsistent alignment across browsers due to vendor prefixes and outdated polyfills. How do you prioritize and execute a long-term cleanup without breaking existing features?

Follow-up Questions

  • What happens if you set flex: 1 on all children but one has a fixed width?
  • How does flex-wrap change the behavior when content overflows?
  • Why might a flex item not shrink even when the container is too small?