Bird
Raised Fist0
CSSmarkup~20 mins

Justify content in CSS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Justify Content Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does justify-content: space-between; do in a flex container?
Imagine you have a row of boxes inside a container. What happens when you use justify-content: space-between; on the container?
AThe boxes are spread out with equal space before the first and after the last box.
BThe boxes are packed at the start with no space between them.
CThe boxes are spread out so the first is at the start, the last is at the end, and equal space is between each box.
DThe boxes are all grouped at the center with equal space around them.
Attempts:
2 left
💡 Hint
Think about how the space is distributed between and around the boxes.
📝 Syntax
intermediate
1:30remaining
Which CSS snippet correctly centers flex items horizontally?
You want to center all items inside a flex container horizontally. Which code snippet does this correctly?
CSS
display: flex;
/* missing justify-content */
Ajustify-content: flex-start;
Bjustify-content: center;
Cjustify-content: space-around;
Djustify-content: stretch;
Attempts:
2 left
💡 Hint
Centering means items are grouped in the middle with equal space on both sides.
rendering
advanced
2:00remaining
What is the visual result of justify-content: space-evenly; in a flex container?
You have five boxes in a row inside a flex container with justify-content: space-evenly;. What will you see?
CSS
display: flex;
justify-content: space-evenly;
ABoxes have equal space between them and also equal space before the first and after the last box.
BBoxes are packed tightly at the start with no space between them.
CBoxes have equal space only between them but no space at the edges.
DBoxes are centered with extra space only on the right side.
Attempts:
2 left
💡 Hint
Think about how space is shared inside the container including edges.
selector
advanced
2:30remaining
Which CSS selector targets only flex containers with justify-content: center;?
You want to style only flex containers that have justify-content: center;. Which selector works?
Adiv.flex-container[style*='justify-content: center']
B.flex-container.justify-content-center
Cdiv.flex-container > *:first-child
Ddiv.flex-container:has([style*='justify-content: center'])
Attempts:
2 left
💡 Hint
Look for a selector that matches inline styles containing the text.
accessibility
expert
3:00remaining
How does justify-content affect keyboard navigation in a flex container?
Consider a horizontal flex container with several focusable buttons. How does changing justify-content impact keyboard users navigating with Tab key?
AIt reverses the tab order when set to <code>flex-end</code>.
BIt changes the tab order to match the visual order of items on screen.
CIt disables keyboard navigation if set to <code>space-between</code>.
DIt does not affect the tab order; keyboard navigation follows the DOM order regardless of visual layout.
Attempts:
2 left
💡 Hint
Think about how keyboard focus moves through elements in HTML.

Practice

(1/5)
1. What does the CSS property justify-content control in a flex container?
easy
A. The vertical alignment of items inside the container
B. The horizontal alignment of items inside the container
C. The size of the container
D. The color of the items

Solution

  1. Step 1: Understand the role of justify-content

    This property controls how items are aligned horizontally inside a flex or grid container.
  2. Step 2: Differentiate from vertical alignment

    Vertical alignment is controlled by align-items, not justify-content.
  3. Final Answer:

    The horizontal alignment of items inside the container -> Option B
  4. Quick Check:

    Justify content = horizontal alignment [OK]
Hint: Justify content aligns items left to right [OK]
Common Mistakes:
  • Confusing justify-content with align-items
  • Thinking it changes item size
  • Assuming it controls colors
2. Which of the following is the correct syntax to center items horizontally using justify-content in a flex container?
easy
A. justify-content: center-items;
B. justify-content: middle;
C. justify-content: align-center;
D. justify-content: center;

Solution

  1. Step 1: Recall valid values for justify-content

    Common valid values include flex-start, center, space-between, and space-around.
  2. Step 2: Identify the correct syntax for centering

    The correct value to center items horizontally is center, so the syntax is justify-content: center;.
  3. Final Answer:

    justify-content: center; -> Option D
  4. Quick Check:

    Centering uses 'center' value [OK]
Hint: Use 'center' exactly to center items [OK]
Common Mistakes:
  • Using invalid values like 'middle' or 'align-center'
  • Missing the colon or semicolon
  • Confusing with align-items syntax
3. Given this CSS and HTML, what will be the horizontal spacing of the items inside the container?
div.container {
  display: flex;
  justify-content: space-between;
  width: 300px;
}

<div class="container">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>
medium
A. Items are grouped together on the left
B. Items are centered with equal space around them
C. Items are evenly spaced with equal space between them
D. Items are aligned to the right

Solution

  1. Step 1: Understand justify-content: space-between;

    This value places the first item at the start, the last item at the end, and evenly distributes space between the items.
  2. Step 2: Visualize the layout

    With three items, the spaces between them are equal, but no extra space is added at the container edges.
  3. Final Answer:

    Items are evenly spaced with equal space between them -> Option C
  4. Quick Check:

    Space-between = equal gaps between items [OK]
Hint: Space-between puts equal gaps only between items [OK]
Common Mistakes:
  • Thinking space-between adds space around edges
  • Confusing with space-around or center
  • Assuming items cluster on one side
4. Identify the error in this CSS code that prevents justify-content from working:
div.container {
  display: block;
  justify-content: center;
}
medium
A. The container must have display: flex; or display: grid; for justify-content to work
B. The property name should be justify-items instead
C. The value 'center' is invalid for justify-content
D. The container needs a fixed width

Solution

  1. Step 1: Check the display property

    justify-content only works on flex or grid containers, but here display is set to block.
  2. Step 2: Understand the requirement for flex/grid

    Without display: flex; or display: grid;, justify-content has no effect.
  3. Final Answer:

    The container must have display: flex; or display: grid; for justify-content to work -> Option A
  4. Quick Check:

    Justify-content needs flex or grid [OK]
Hint: Use flex or grid display for justify-content to work [OK]
Common Mistakes:
  • Using justify-content on block containers
  • Confusing justify-content with justify-items
  • Thinking value 'center' is invalid
5. You want to create a navigation bar with 4 links spaced evenly across the width, but with equal space around each link (including edges). Which justify-content value should you use in your flex container?
hard
A. space-around
B. flex-start
C. center
D. space-between

Solution

  1. Step 1: Understand the difference between space-between and space-around

    space-between puts equal space only between items, no space at edges. space-around adds equal space around each item, including edges.
  2. Step 2: Match requirement to property value

    Since the requirement is equal space around each link including edges, space-around is the correct choice.
  3. Final Answer:

    space-around -> Option A
  4. Quick Check:

    Space-around = equal space around all items [OK]
Hint: Use space-around for equal space including edges [OK]
Common Mistakes:
  • Choosing space-between which skips edges
  • Using center which groups items
  • Using flex-start which aligns left only