Difference Between align-items and align-content in Flexbox
Both align-items and align-content are Flexbox properties used to align items along the cross axis, but they serve different purposes depending on the number of flex lines in the container.
align-items aligns individual items within a single flex line along the cross axis.
align-content aligns multiple lines of flex items (when wrapping occurs) within the flex container.
align-items works regardless of whether items wrap or not.
align-content only applies when there is extra space in the cross axis and when flex-wrap is enabled.
align-items controls how each item is aligned within its line, while align-content controls how the lines themselves are spaced inside the container.
In this example, align-items: center vertically centers each item within its line, while align-content: space-between distributes the multiple lines evenly across the container height.
Use align-items for aligning items within a single row or column.
Use align-content when dealing with multiple flex lines (using flex-wrap).
Combine both for fine-tuned control over layout alignment along the cross axis.
If your layout has only one line of items, align-content has no visible effect.
You're building a card grid with 3 items per row, and they're all sticking to the top — how would you center them vertically within each row?
If you set align-items: center on a flex container with 5 items in one line, but the container is taller than the items, where do the items appear?
What happens if you apply align-content: space-between to a flex container that only has one line of items?
A responsive product grid breaks on mobile — items are stacking but the vertical spacing looks uneven. You've set align-items: center, but the content still looks misaligned. What’s likely wrong?
Your team’s component library has a flex-based sidebar that sometimes has 1 item, sometimes 5. When it has multiple items, the vertical spacing between them feels off. How would you fix it without breaking the single-item case?
A designer complains that a modal’s content is aligned to the top on tablets but centered on desktop. You’ve used align-items: center — what could be causing this inconsistency?
You're designing a dynamic dashboard with collapsible panels that can wrap into multiple rows. How do you ensure consistent vertical spacing between rows when the container height changes dynamically, and why can't you just use align-items?
A legacy component uses flexbox with flex-wrap: wrap and align-content: stretch, but now it's causing overflow on low-res screens. How would you refactor this to be more robust without breaking existing layouts?
In a high-performance UI library, you notice that align-content is causing layout thrashing on mobile devices during resize. How would you optimize this without losing visual consistency?
You're leading a cross-team effort to unify layout systems across 12 product surfaces. Some teams use align-content for spacing, others use margins — how do you standardize this without introducing regressions or performance issues?
Your company is migrating from a legacy grid system to CSS Flexbox. Teams are misusing align-content as a spacing tool because they don’t understand its line-based behavior. How do you architect a training and linting strategy to prevent this at scale?
A design system component that uses align-content works fine in the demo but breaks in production when content is dynamically loaded. How do you design the API to make this behavior predictable and safe for engineers across teams?