Questions
8 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?
08 / 51

How do you change the direction of items in a flex container?

Changing Flex Direction in CSS

The direction of items in a flex container is controlled using the flex-direction property. This determines the main axis along which the flex items are laid out.

Key Points About Flex Direction
  1. 1

    flex-direction: row (default) lays out items horizontally from left to right.

  2. 2

    flex-direction: row-reverse lays out items horizontally from right to left.

  3. 3

    flex-direction: column lays out items vertically from top to bottom.

  4. 4

    flex-direction: column-reverse lays out items vertically from bottom to top.

  5. 5

    Changing the direction affects how main-axis properties like justify-content work, while cross-axis properties like align-items adjust accordingly.

Example: Changing Flex Direction

In this example, the .container flex items are arranged in a column because of flex-direction: column. Changing flex-direction to row or other values will reposition the items along the main axis accordingly.

Best Practices
  1. 1

    Use flex-direction to control whether your layout flows horizontally or vertically.

  2. 2

    Combine with justify-content and align-items to fine-tune item alignment along the main and cross axes.

  3. 3

    Test different directions for responsive design to ensure layouts adapt correctly on various screen sizes.

  4. 4

    Avoid using too many nested flex containers to maintain layout clarity and performance.

Difficulty: 3/10
Topics: flex-direction, flex-wrap, row vs column layout

Scenario Questions

0-2 years experience
  1. 1

    You're building a mobile menu that should stack vertically on small screens but show horizontally on desktop. How would you use flex-direction to achieve that with a media query?

  2. 2

    A button group is rendering left-to-right, but the designer wants them right-to-left. What CSS property do you change and what value do you set?

  3. 3

    If you set flex-direction: column on a container with three divs, what order do they appear in visually?

2-5 years experience
  1. 1

    A responsive card grid breaks on tablet — items are wrapping strangely even though you set flex-wrap: wrap. What could be causing it, and how would you debug whether flex-direction is part of the issue?

  2. 2

    Your team’s component library has a flex-based navigation bar that works fine in LTR languages, but when you enable RTL support, the icons and text reverse incorrectly. How do you fix this without duplicating CSS?

  3. 3

    A feature toggle switches between horizontal and vertical layouts for a dashboard widget. Users report that focus order gets messed up when toggling. What’s the root cause and how do you fix it?

5-8 years experience
  1. 1

    You’re designing a dynamic layout system where users can reorder sections via drag-and-drop. How do you handle flex-direction changes without breaking screen reader navigation or causing layout thrashing?

  2. 2

    A legacy component uses flex-direction: row-reverse for visual alignment, but now we need to support RTL and accessibility. What’s the cleanest way to migrate this without breaking existing styles or introducing a11y issues?

  3. 3

    In a high-performance dashboard with 50+ dynamic flex items, switching flex-direction on resize causes jank. How would you optimize this without sacrificing responsiveness?

8+ years experience
  1. 1

    Our design system supports 12+ languages including RTL scripts. How do you architect the flex layout primitives to avoid per-language CSS overrides while ensuring correct visual and semantic order across all locales?

  2. 2

    We’re migrating from a float-based grid to flexbox across 200+ legacy pages. Many rely on row-reverse for visual alignment. What’s your strategy to refactor this safely without breaking accessibility, SEO, or internationalization?

  3. 3

    A cross-team component library uses flex-direction dynamically based on viewport, but different teams are overriding it inconsistently. How do you enforce a coherent layout strategy at scale without stifling autonomy?

Follow-up Questions

  • What happens if you have text wrapping inside a flex item when flex-direction is column?
  • How would you debug a layout where items appear stacked vertically when you expected them to be horizontal?
  • Why might flex-direction: row-reverse break an accessibility screen reader order?