Questions
2 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?
02 / 51

What problem does Flexbox solve compared to traditional layouts like float or inline-block?

Why Flexbox is Better Than Float and Inline-Block Layouts

Traditional CSS layout methods like float and inline-block often require hacks, extra markup, and complex calculations to achieve alignment and spacing. Flexbox was introduced to simplify these tasks and provide a more robust and predictable layout system.

Problems with Traditional Layouts
  1. 1

    Floats were originally intended for wrapping text around images, not for full layouts, leading to clearfix hacks and unexpected collapses.

  2. 2

    Inline-block elements create unwanted whitespace due to HTML formatting and are difficult to evenly distribute.

  3. 3

    Vertical alignment is tricky with floats and inline-blocks, often requiring extra wrappers or negative margins.

  4. 4

    Responsive adjustments require more calculations and media queries to maintain proper spacing.

How Flexbox Solves These Problems
  1. 1

    Flexbox provides easy horizontal and vertical alignment of items along main and cross axes without extra markup.

  2. 2

    It automatically distributes space between items with properties like justify-content and align-items.

  3. 3

    Flex items can grow, shrink, or wrap to fill available space dynamically using flex-grow, flex-shrink, and flex-wrap.

  4. 4

    It simplifies responsive design, allowing layouts to adapt naturally without complex calculations or workarounds.

Example: Flexbox vs Float

In this comparison, the float-based layout requires a clearfix and careful width calculations, while the Flexbox layout automatically aligns and spaces items evenly, wraps them on smaller screens, and is easier to maintain.

Difficulty: 6/10
Topics: Flexbox alignment, Layout responsiveness, Float vs Flexbox limitations

Scenario Questions

0-2 years experience
  1. 1

    How would you center a button vertically and horizontally inside a header using flexbox, and what happens if you try to do the same with float?

  2. 2

    What happens if you set width: 100% on a flex item inside a container with flex-wrap: wrap — does it behave differently than with inline-block?

  3. 3

    You have three divs side-by-side using inline-block, but there’s unwanted space between them. How would you fix that with flexbox instead?

2-5 years experience
  1. 1

    A card component with an image and text breaks on mobile — the text overflows and the image shrinks too much. How would you diagnose and fix this using flexbox properties?

  2. 2

    Your team’s legacy layout uses float for a three-column dashboard, but it’s breaking when content length varies. Why is flexbox a better fit here, and what specific properties would you use to make it robust?

  3. 3

    A modal popup’s content is misaligned on iOS Safari — the flex container doesn’t stretch properly. What common edge case might be causing this, and how would you fix it?

5-8 years experience
  1. 1

    You’re designing a dynamic dashboard with collapsible panels that need to reflow responsively. Why would you choose flexbox over CSS Grid here, and what performance or accessibility tradeoffs should you consider?

  2. 2

    A component library uses flexbox for all layouts, but in high-frequency rendering scenarios (like real-time dashboards), users report layout thrashing. How would you investigate and optimize this?

  3. 3

    How would you design a flexible form layout that adapts from desktop (side-by-side labels and inputs) to mobile (stacked) while maintaining accessibility and form validation alignment — and what flexbox pitfalls might trip up junior engineers?

8+ years experience
  1. 1

    Your company is migrating from a float-based legacy UI framework to modern CSS. What architectural strategy would you propose to phase out float usage without breaking hundreds of components, and how would you enforce consistency across teams?

  2. 2

    You’re defining a design system’s layout primitives. Why would you choose flexbox as the default for one-dimensional layouts over Grid, and how do you communicate the long-term maintenance implications to frontend teams across regions?

  3. 3

    A global product uses flexbox for core layouts, but RTL languages break alignment due to hardcoded margin values. How would you architect a solution that scales across 20+ languages without duplicating layout logic?

Follow-up Questions

  • How would you debug a flex item that’s not aligning as expected in a responsive layout?
  • What happens when you mix flexbox with float on the same container?
  • Why might you avoid flexbox for a grid-like layout with complex row/column dependencies?