Questions
3 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?
03 / 51

How do you create a flex container?

Creating a Flex Container in CSS

A flex container is created by applying display: flex or display: inline-flex to a parent element. This enables the Flexbox layout model, allowing the children (flex items) to be aligned and distributed along the main and cross axes.

Key Points
  1. 1

    display: flex makes the container a block-level flex container.

  2. 2

    display: inline-flex makes the container an inline-level flex container.

  3. 3

    Flex items are the direct children of a flex container.

  4. 4

    Flex container properties like justify-content, align-items, align-content, and flex-wrap control the alignment, spacing, and wrapping of the items.

Example: Basic Flex Container

In this example, .container is a flex container. The .item elements are flex items, evenly spaced along the main axis and centered along the cross axis using justify-content and align-items.

Best Practices
  1. 1

    Use display: flex for one-dimensional layouts (row or column).

  2. 2

    Combine flex-wrap: wrap for responsive multi-line layouts.

  3. 3

    Understand the main axis vs cross axis for proper alignment.

  4. 4

    Test across browsers to ensure consistent behavior.

Difficulty: 3/10
Topics: flex-direction, justify-content, align-items

Scenario Questions

0-2 years experience
  1. 1

    How would you make three buttons sit side by side in a header with equal spacing between them using flexbox?

  2. 2

    What happens if you set display: flex on a div but don't specify flex-direction — how do the children arrange themselves by default?

  3. 3

    You have a card with a title and a button, but the button is stuck to the top — how do you center it vertically using flexbox?

2-5 years experience
  1. 1

    A responsive navigation bar breaks on mobile — the items stack vertically but overflow the container. What could be causing this, and how would you fix it?

  2. 2

    Your team’s component library has a flex-based card that looks fine in dev but misaligns in production. What would you check first, and why?

  3. 3

    A form layout with labels and inputs uses flexbox, but on small screens, the inputs get squished. How would you adjust the flex properties to preserve usability?

5-8 years experience
  1. 1

    You’re designing a dynamic dashboard with collapsible panels — how would you structure the flex container to ensure smooth resizing without layout thrashing or overflow issues?

  2. 2

    A legacy UI uses floats for a grid, but you’re migrating to flexbox. What edge cases in browser support or content overflow should you anticipate, and how would you handle them?

  3. 3

    How would you design a flex-based carousel with variable-width items that still maintains visual balance and avoids clipping on low-resolution devices?

8+ years experience
  1. 1

    You’re leading a cross-team effort to standardize layout systems across 20+ products — why would you choose flexbox over CSS Grid for certain components, and how do you enforce consistency without over-constraining designers?

  2. 2

    A legacy monorepo has hundreds of flex containers with inconsistent property usage. How would you design a migration strategy to refactor them without breaking UIs in production?

  3. 3

    How would you architect a themable layout system using flexbox that supports RTL, dynamic font scaling, and accessibility requirements across global markets — and what metrics would you track to validate performance and maintainability?

Follow-up Questions

  • What happens if you forget to set a height on the flex container when using align-items: stretch?
  • How would you debug a flex item that isn't shrinking even though you set flex-shrink: 1?
  • Why might flex-wrap: wrap not behave as expected when the container has a fixed width?