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

What does the flex shorthand property represent?

Understanding the flex Shorthand Property in Flexbox

The flex shorthand property in CSS defines how a flex item grows, shrinks, and sets its base size within a flex container. It combines three individual properties — flex-grow, flex-shrink, and flex-basis — into a single, concise declaration.

Syntax
  1. 1

    flex: <flex-grow> <flex-shrink> <flex-basis>;

  2. 2

    Each value is optional, and omitted values fall back to defaults.

Components of the flex Shorthand
  1. 1

    flex-grow: Defines how much a flex item will grow relative to the rest when space is available (default: 0).

  2. 2

    flex-shrink: Defines how much a flex item will shrink relative to others when space is limited (default: 1).

  3. 3

    flex-basis: Defines the initial size of the item before space distribution (default: auto).

Example: Using the flex Shorthand

In this example, Item 2 grows twice as fast as Items 1 and 3 because its flex-grow value is 2. All items start with a base width of 150px and shrink equally if necessary.

Common Shorthand Values
  1. 1

    flex: 1; → Equivalent to flex: 1 1 0; (items grow and shrink equally).

  2. 2

    flex: auto; → Equivalent to flex: 1 1 auto;.

  3. 3

    flex: none; → Equivalent to flex: 0 0 auto; (fixed size, no growth or shrink).

  4. 4

    flex: initial; → Equivalent to flex: 0 1 auto; (default behavior).

Best Practices
  1. 1

    Use flex: 1 to evenly distribute available space among items.

  2. 2

    Use flex: none for fixed-size elements like buttons or logos.

  3. 3

    Combine flex-grow and flex-basis strategically for responsive layouts.

  4. 4

    Avoid mixing width and flex properties unless necessary for layout control.

Difficulty: 3/10
Topics: flex-grow, flex-shrink, flex-basis

Scenario Questions

0-2 years experience
  1. 1

    You're building a two-column layout where one column should take up twice as much space as the other — how would you use flex shorthand to achieve that?

  2. 2

    A button and a text input are side by side, but the button is way too wide. You set flex: 1 on both, but it doesn't fix it. What's likely wrong?

  3. 3

    If you set flex: 0 1 100px on an element, what does each number mean and how will it behave when the container shrinks?

2-5 years experience
  1. 1

    A responsive card grid breaks on mobile — items overflow or collapse weirdly. You suspect flex shorthand misuse. How would you diagnose and fix it?

  2. 2

    Your team’s design system uses flex: 1 everywhere for equal-width columns, but now a new component needs one item to be narrower. What’s the risk of just changing one flex value, and how would you handle it?

  3. 3

    A modal with three buttons is misaligned on iOS Safari. All buttons have flex: 1, but one is visibly smaller. What could be causing this, and how would you investigate?

5-8 years experience
  1. 1

    You're designing a dynamic dashboard with collapsible panels that use flex. How do you ensure smooth resizing and avoid layout thrashing when users toggle panels frequently?

  2. 2

    A legacy component uses flex: auto on everything, and now it's causing performance issues on low-end devices. How would you refactor it without breaking existing layouts?

  3. 3

    In a complex form with nested flex containers, users report inconsistent input widths across browsers. How do you isolate whether it's a flex shorthand misconfiguration or a browser rendering quirk?

8+ years experience
  1. 1

    Your company is migrating from a float-based grid to flexbox at scale. How do you prioritize which components to refactor first, and how do you prevent regressions across 50+ product pages?

  2. 2

    You're designing a cross-team layout system used by 20+ product teams. How do you standardize flex shorthand usage to avoid inconsistent behaviors while still allowing flexibility for edge cases?

  3. 3

    A critical feature relies on flex-based layouts that break when internationalized text expands. How do you architect a resilient layout system that handles dynamic content growth without requiring constant CSS overrides?

Follow-up Questions

  • What happens if you set flex: 1 on one item but leave another with default flex values?
  • How would you debug a layout where items aren't shrinking as expected?
  • Why might flex: 1 not work the way you expect inside a nested flex container?