Flexbox playground — interactive CSS flex layout lab with live preview and copyable styles

This free online flexbox playground helps you learn and ship CSS Flexible Box Layout without memorizing every keyword. Adjust flex-direction, flex-wrap, justify-content, align-items, align-content, and gap on the container, then click any demo item to tune flex-grow, flex-shrink, flex-basis, align-self, and order. The preview updates immediately; use Copy CSS (copy icon) to paste production rules into your codebase. Everything runs in your browser. For two-dimensional templates, continue with the CSS Grid playground; for accessible color pairs on top of your layout, use the color contrast checker. Browse the full design and color tools on the home page.

Flex items

Click a colored box to edit that item's flex properties.

Container
Selected item (1)

Rename .flex-container to match your markup. Child rules use :nth-child so order matches the DOM.

Why developers use a flexbox playground for real UI work

Searchers look for a flexbox visualizer, flexbox sandbox, or CSS flex generator because flexbox behavior depends on main axis vs cross axis, whether items wrap, and how free space is distributed. Toggling justify-content: space-between next to center in a live preview is faster than editing CSS in DevTools and losing your place. This page targets those workflows with numbered demo items, clear container controls, and a textarea that mirrors what you would ship—plus optional cleanup of your broader stylesheet with our CSS formatter and minifier.

Common product tasks— responsive navigation, splitting a toolbar into left and right groups, vertically centering icons beside text, and building equal-height card footers—are all flexbox-shaped problems. Pair this lab with the border radius generator and box shadow generator when you are polishing cards and buttons built with flex rows.

Flexbox guide: main axis, cross axis, and when wrapping matters

In flex-direction: row, the main axis runs horizontally and justify-content spreads items along that line. In column, the main axis is vertical, so justify-content affects vertical packing instead—often surprising the first time you prototype a dashboard. The cross axis is perpendicular: align-items lines up items on that axis for each row or column. When flex-wrap is wrap or wrap-reverse, you get multiple flex lines; align-content controls how those lines are spaced along the cross axis (useful for chip lists and tag clouds). Use the playground to flip direction and wrap while watching the same numbered items move.

How to use this flexbox playground (step by step)

  1. Under Container, set flex-direction and flex-wrap, then choose justify-content, align-items, and align-content. Adjust the gap slider for consistent spacing without margins on every child.
  2. Click a colored box in the preview to select it. In Selected item, change flex-grow and flex-shrink, pick a flex-basis mode (auto, 0, or a custom pixel width), and optionally override align-self or order.
  3. Use Add item and Remove to change how many flex items participate—up to twelve—then Reset demo to restore the starter layout.
  4. Scroll to Generated CSS and press Copy CSS (copy icon). Rename .flex-container to match your component class or styled wrapper.

Flexbox vs CSS Grid for page layout

Flexbox excels at distributing items in a single row or column and handling variable content (think form fields that grow, icons that stay fixed). Grid excels at two-dimensional areas and explicit tracks. Many production pages use Grid for the outer shell and Flexbox inside cards and headers. After you settle flex behavior here, open the CSS Grid playground when you need template columns and row spans. For background decoration on flex children, the gradient generator pairs well with flex rows and hero sections.

Related design and developer tools

More utilities from our catalog:

  • Color Picker & ConverterPick colors and copy HEX, RGB, HSL, and CMYK values for design systems and handoff.
  • Color Contrast CheckerTest text and background pairs against WCAG AA and AAA contrast ratios for accessible UI.
  • Color Palette GeneratorFrom one base hue, build complementary, triadic, analogous, and monochrome palettes.
  • Gradient GeneratorDesign linear and radial gradients visually and copy production-ready CSS in seconds.
  • Tint & Shade GeneratorGenerate lighter tints and darker shades from a brand color for consistent UI scales.
  • Color Blindness SimulatorPreview images or palettes under common color-vision deficiencies to validate inclusive design.
  • Box Shadow GeneratorTune offset, blur, spread, color, and inset shadows with live preview and copyable CSS.
  • Border Radius GeneratorAdjust each corner visually and export shorthand border-radius for cards and buttons.
  • CSS Gradient GeneratorBuild multi-stop gradients with angles and stops—outputs clean, modern CSS gradients.
  • CSS Grid PlaygroundPrototype grid templates, gaps, and placement with instant visual feedback.
  • Favicon GeneratorCreate favicon.ico and PNG sizes from an image or text for every device and browser tab.

Frequently asked questions

What is a flexbox playground?
A flexbox playground is an interactive CSS layout lab where you change flex container properties (direction, wrap, justify-content, align-items, gap) and flex item properties (grow, shrink, basis, align-self, order) while a live preview updates instantly. You copy the generated CSS into your stylesheet or component styles—ideal for learning flexbox without guessing in DevTools.
When should I use CSS Flexbox instead of CSS Grid?
Use Flexbox for one-dimensional layouts: rows or columns of components that should distribute space, wrap, or align along a single axis—navigation bars, toolbars, form rows, and card footers. Use CSS Grid when you need two-dimensional templates with explicit rows and columns. Many UIs combine both: Grid for the page shell and Flexbox inside components. After exploring flex here, you can prototype grid-heavy layouts in our CSS Grid Playground.
What does justify-content control in Flexbox?
justify-content distributes flex items along the main axis (horizontal in row, vertical in column). Values like flex-start and flex-end pin items to one side; center centers them; space-between pushes the first and last items to the edges with equal gaps between; space-around and space-evenly add symmetric spacing. It does not move wrapped rows as a whole—that is align-content when flex-wrap is not nowrap.
What is the difference between align-items and align-self?
align-items sets the default cross-axis alignment for every flex item in the container (stretch, flex-start, flex-end, center, baseline). align-self overrides that default for a single item. In this tool, select an item in the preview to edit its align-self while keeping siblings on the container default—handy for centering one odd button in a row.
How do flex-grow, flex-shrink, and flex-basis work together?
Together they form the flex shorthand. flex-grow is how much an item expands when extra space exists (0 means do not grow). flex-shrink is how much it contracts when space is tight (0 means do not shrink). flex-basis is the starting size before growing or shrinking—auto uses the item’s width or height from content, 0 makes flex-grow share space more predictably in equal-width layouts. The playground outputs flex: grow shrink basis for clarity.
Does this tool send my layout to a server?
No. All state runs in your browser: the preview and CSS string are computed locally. Nothing is uploaded when you copy CSS. If you use a future import feature, parsing would still happen client-side unless explicitly stated otherwise.
Can I use the copied CSS in Tailwind CSS or styled-components?
Yes. Paste the rules into a global stylesheet, a CSS module, or the style prop as a string. In Tailwind, many flex utilities map 1:1 (flex, flex-row, justify-center, gap-4). This playground helps when you need exact values, custom gaps in pixels, or nth-child rules that are faster to prototype visually than typing utilities from memory.