Questions
1 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?
01 / 51

What is Flexbox in CSS?

Understanding Flexbox in CSS

Flexbox, or the Flexible Box Layout, is a CSS layout model designed to provide an efficient way to align and distribute space among items in a container, even when their size is unknown or dynamic.

Key Concepts
  1. 1

    Flex container: The parent element with display: flex or display: inline-flex.

  2. 2

    Flex items: The direct children of a flex container that are laid out according to flexbox rules.

  3. 3

    Main axis and cross axis: Flex items are arranged along the main axis (default horizontal) and can be aligned along the cross axis (default vertical).

  4. 4

    Flex properties like justify-content, align-items, align-self, and flex-wrap control the positioning and spacing of flex items.

Example: Basic Flexbox Layout

In this example, the .container is a flex container, and its children .item are flex items. They are evenly spaced along the main axis, and each item expands equally because of flex: 1.

Best Practices
  1. 1

    Use Flexbox for one-dimensional layouts (either row or column).

  2. 2

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

  3. 3

    Understand the difference between justify-content (main axis) and align-items (cross axis) for proper alignment.

  4. 4

    Test layouts across different screen sizes to ensure items behave as expected.

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

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 width: 100% on a flex item inside a container with flex-direction: row?

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’s likely wrong and how would you fix it?

  2. 2

    Your team’s modal component looks fine in Chrome but misaligns in Safari. What Flexbox quirks might be causing this and how would you investigate?

5-8 years experience
  1. 1

    You’re designing a dynamic dashboard with collapsible panels that must maintain vertical alignment when resized. How would you structure the Flexbox layout to avoid layout thrashing and ensure smooth transitions?

  2. 2

    A legacy component uses absolute positioning for alignment. You want to migrate it to Flexbox without breaking existing layouts. What edge cases would you test and how would you prioritize the refactor?

8+ years experience
  1. 1

    Your company has 20+ UI components using Flexbox inconsistently — some rely on flex-grow, others use margins for spacing. How would you design a design system standard for Flexbox usage across teams?

  2. 2

    You’re migrating a legacy app from float-based layouts to Flexbox. What long-term maintenance risks do you anticipate, and how would you structure the migration to minimize regressions and enable team autonomy?

Follow-up Questions

  • What happens if you set flex-grow: 1 on one child but not the others?
  • How would you debug a flex item that’s not aligning as expected?
  • Why might justify-content: center not work as intended in a nested flex container?