What Is Flexbox?

CSS Flexbox is a layout model designed for distributing space and aligning items within a container — even when their sizes are unknown or dynamic. Before Flexbox, centering elements and creating equal-height columns required hacks with floats, tables, or absolute positioning. Flexbox solved all of that with a clean, intuitive property system.

This playground lets you experiment with every Flexbox property in real time: flex-direction, justify-content, align-items, flex-wrap, gap, and individual item properties like flex-grow, flex-shrink, and align-self. See exactly how each property affects your layout without writing a line of code.

Key Flexbox Properties

flex-direction controls the main axis (row or column). justify-content distributes items along the main axis (start, center, space-between, space-around, space-evenly). align-items aligns items on the cross axis (stretch, center, start, end, baseline). flex-wrap determines whether items wrap to new lines or stay in one row.

Tips for Using Flexbox

How to Use This Flexbox Playground

  1. Set the flex container properties — Configure flex-direction, justify-content, align-items, flex-wrap, and gap on the parent container.
  2. Add and remove flex items — Add child elements and see how they distribute within the container based on your settings.
  3. Adjust individual item properties — Set flex-grow, flex-shrink, flex-basis, and align-self on individual items to control their sizing behavior.
  4. Experiment with layouts — Try common patterns — centered content, sidebar+main, equal columns, holy grail layout — using different property combinations.
  5. Copy the CSS — Grab the complete flexbox CSS for both the container and items.

Tips and Best Practices

Frequently Asked Questions

What is CSS Flexbox?
CSS Flexbox (Flexible Box Layout) is a one-dimensional layout model that distributes space among items in a container along a single axis. It simplifies centering, spacing, alignment, and responsive reordering without floats or positioning hacks.
When should I use Flexbox vs Grid?
Use Flexbox for one-dimensional layouts — a single row or column of items. Use CSS Grid for two-dimensional layouts where you need control over both rows and columns simultaneously. Many modern layouts combine both.
How do I center a div with Flexbox?
Apply display: flex; justify-content: center; align-items: center; to the parent container. This centers the child both horizontally and vertically — the most common and simplest Flexbox pattern.
What is CSS Flexbox?+
Flexbox (Flexible Box Layout) is a CSS layout model that distributes space and aligns items within a container — either horizontally (row) or vertically (column). It simplifies common layout patterns like centering, equal-height columns, sticky footers, and responsive navigation that were difficult or hacky with floats and positioning.
When should I use Flexbox vs CSS Grid?+
Use Flexbox for one-dimensional layouts — a row of buttons, a navigation bar, centering a single element, or distributing items along one axis. Use CSS Grid for two-dimensional layouts — page layouts with rows AND columns, card grids, and complex dashboards. They can be combined: Grid for the page layout, Flexbox for components within grid cells.
What does flex: 1 1 0 mean?+
It's shorthand for flex-grow: 1 (take available space), flex-shrink: 1 (shrink if needed), flex-basis: 0 (start from zero width/height). This makes the item grow to fill its share of the container's available space equally with other flex: 1 siblings. It's the most common flex shorthand.

📖 Learn More

Related Article CSS Flexbox vs Grid: When to Use Which → Related Article How to Use CSS Flexbox →

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service