---
name: css-flexbox-layout-formatter
description: "Gives you a copy-ready Flexbox snippet and matching HTML skeleton from a handful of choices, so a prototype row or column layout is on screen in a minute, with each property explained. Use when someone wants a quick Flexbox prototype from a few settings such as direction, justify, align, item count, and gap, with the HTML to try it. Do not use for diagnosing an existing layout, multi-row responsive grids, or page-level layouts with headers and footers. Related topics: coding, css."
---

# CSS Flexbox Layout Formatter

Gives you a copy-ready Flexbox snippet and matching HTML skeleton from a handful of choices, so a prototype row or column layout is on screen in a minute, with each property explained.

## When to use

Use this skill when someone wants a quick Flexbox prototype from a few settings such as direction, justify, align, item count, and gap, with the HTML to try it. Do not use it for diagnosing an existing layout, multi-row responsive grids, or page-level layouts with headers and footers.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Write the container rule with display: flex and the chosen direction, justify, align, and gap, commenting each working declaration.
3. Implement the item size pattern with the flex shorthand and add a modifier class only when one item behaves differently.
4. Generate the HTML skeleton with the exact item count, numbered content, and a visible background per item.
5. Explain in plain sentences how the chosen justify and align values place items on each axis and what happens when space runs out.

## Inputs

- **Container width** (free text, e.g. "100% or 800px")
- **Flex direction** (choose one: row, row-reverse, column, column-reverse)
- **Justify content** (choose one: flex-start, flex-end, center, space-between, space-around, space-evenly)
- **Align items** (choose one: stretch, flex-start, flex-end, center, baseline)
- **Number of items** (number from 1 to 12)
- **Item size pattern** (choose one: Equal widths, Fixed widths, Content-sized, First item grows, Last item grows, Shrink to fit)
- **Gap between items (px)** (number from 0 to 64)

## Output

One fenced code block with the CSS and HTML (CSS first, commented), then a short paragraph explaining the chosen properties.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### CSS Flexbox Layout Formatter

Build a Flexbox snippet and the HTML to demonstrate it from these settings.

- Container width: {{Container width}}
- Flex direction: {{Flex direction}}
- Justify content: {{Justify content}}
- Align items: {{Align items}}
- Number of items: {{Number of items}}
- Item size pattern: {{Item size pattern}}
- Gap between items (px): {{Gap between items (px)}}

Write the container rule first with display: flex and the chosen direction, justify, align, and gap, then one item rule that implements the size pattern with the flex shorthand (flex: 1 1 0 for equal widths, flex: 0 0 240px for fixed widths, flex: 0 1 auto for content-sized) and a modifier class for the growing item when the pattern needs one. Add a short comment on each declaration that is doing real work. Generate the HTML skeleton with exactly the requested number of items, numbered so the order is visible, and give each a visible background so the layout can be seen without extra styling. Then explain in a few sentences how the chosen justify and align values place the items on the main and cross axis, and what changes when the container is narrower than the items.

## Pitfalls

- Using width on items for equal columns instead of flex: 1 1 0, which stops working as soon as the gap or padding changes.
- Forgetting that align-items: stretch is the default, so a baseline or center choice silently changes item heights.
- Generating a skeleton with a different number of items than requested, which hides how the pattern distributes space.
