Flexbox & Grid Questions with Answers

6 practice questions on Flexbox & Grid (React & Web) with answers and step-by-step solutions. Try 6 samples below, then practise all 6 free in the AptiNest app.

Sample questions

Question 1Easy

With display: flex and the default flex-direction, along which axis does justify-content align items?

  1. Both axes
  2. Neither; it only affects grid
  3. Horizontally (the main axis)
  4. Vertically (the cross axis)

Answer: C. Horizontally (the main axis)

Explanation

The default flex-direction is row, so the main axis is horizontal. justify-content works on the main axis and align-items on the cross axis.

Step-by-step solution

  1. Flex-direction defaults to row, so the main axis runs left to right.
  2. Justify-content works along the main axis.
  3. So justify-content aligns items horizontally, which is option C.

Why the other options are wrong

  • A. Justify-content does not work on the cross axis, so it does not act on both axes.
  • B. Justify-content works in flex layouts; it is not only for grid.
  • D. The vertical direction is the cross axis here, and align-items controls it, not justify-content.

Tip: Justify-content is the main axis; align-items is the cross axis.

Question 2Easy

Which property adds space between flex or grid items without adding outer margins?

  1. gap
  2. padding
  3. spacing
  4. margin-between

Answer: A. gap

Explanation

gap (with row-gap and column-gap) sets the gutters between items in both flex and grid layouts.

Step-by-step solution

  1. The gap property sets the space between flex or grid items.
  2. It uses no outer margin, so the edges of the container stay the same.
  3. So the correct answer is option A, gap.

Why the other options are wrong

  • B. Padding adds space inside the container, not between items.
  • C. Spacing is not a CSS property.
  • D. Margin-between is not a CSS property.

Tip: Use gap for spacing between flex and grid items instead of margins on each item.

Question 3Easy

What layout does grid-template-columns: repeat(3, 1fr) produce?

  1. Three rows of equal height that share the available space
  2. Three columns that are each exactly 1 pixel wide
  3. A single column that is three fractions (3fr) wide
  4. Three equal-width columns sharing the available space

Answer: D. Three equal-width columns sharing the available space

Explanation

fr is a fraction of the free space. Three 1fr tracks split the width equally.

Step-by-step solution

  1. repeat(3, 1fr) expands to 1fr 1fr 1fr.
  2. That makes three columns.
  3. Each fr takes an equal share of the available space.

Why the other options are wrong

  • A. grid-template-columns defines columns, not rows.
  • B. fr is a fraction of space, not pixels.
  • C. It is three columns, not a single one.

Tip: 3 x 1fr = three equal columns.

Question 4Medium

What does flex: 1 on a flex item mean?

  1. order: 1
  2. flex-grow: 1, flex-shrink: 0, flex-basis: auto
  3. flex-grow: 1, flex-shrink: 1, flex-basis: 0%
  4. width: 100%

Answer: C. flex-grow: 1, flex-shrink: 1, flex-basis: 0%

Explanation

The shorthand flex: 1 sets grow 1, shrink 1 and a basis of 0%, so items with flex: 1 share the free space equally.

Step-by-step solution

  1. flex: 1 is shorthand for flex: 1 1 0%.
  2. That means flex-grow 1, flex-shrink 1, flex-basis 0%.
  3. Items share free space equally.

Why the other options are wrong

  • A. order is a separate property.
  • B. That describes flex: auto-like behaviour, with a shrink of 0 and basis auto.
  • D. flex: 1 does not set width to 100%.

Tip: Flex 1 means share space equally.

Question 5Medium

In a grid, what does grid-column: 1 / 3 on an item do?

  1. Spans from line 1 to line 3, covering two columns
  2. Places the item in the first third of the row
  3. Places the item in column 3 only
  4. Spans three columns, from column 1 to column 3

Answer: A. Spans from line 1 to line 3, covering two columns

Explanation

The values are grid line numbers, not column numbers. Lines 1 to 3 enclose columns 1 and 2.

Step-by-step solution

  1. Grid-column values are grid line numbers, not column numbers.
  2. Line 1 is the left edge of column 1, and line 3 is the edge after column 2.
  3. So the item covers columns 1 and 2, spanning two columns, which is option A.

Why the other options are wrong

  • B. The values are grid lines, not fractions of a row.
  • C. The item covers two columns, not only column 3.
  • D. Line 3 is the edge after column 2, so the item spans two columns, not three.

Tip: Grid lines are numbered from 1; a span from line a to line b covers b - a columns.

Question 6Medium

A container has display: flex; flex-direction: column; justify-content: center;. How are its children positioned?

  1. Centered in both directions
  2. Centered vertically
  3. Centered horizontally
  4. Stretched to fill the width only

Answer: B. Centered vertically

Explanation

With flex-direction: column, the main axis is vertical, so justify-content centers the children vertically.

Step-by-step solution

  1. Flex-direction: column makes the main axis vertical.
  2. Justify-content works along the main axis, so it centers the children vertically.
  3. The horizontal axis is the cross axis and is not centered, so the answer is option B.

Why the other options are wrong

  • A. Only the vertical axis is centered, because justify-content acts only on the main axis.
  • C. Horizontal centering would need align-items: center in a column layout.
  • D. The children are not stretched; justify-content centers them.

Tip: In a column flex container, justify-content works vertically and align-items works horizontally.

Practise all 6 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all React & Web topics · All topics