---
name: css-flexbox-layout-analyzer
description: "Explains why a Flexbox container is not producing the layout you want and returns the corrected container and item CSS as structured JSON, ready to drop into a build tool or a review comment. Use when a Flexbox container's CSS does not produce the intended alignment or sizing and the user wants the issues and fixed CSS returned as JSON. Do not use for layouts that need CSS Grid, step-by-step debugging with the HTML in hand, or writing new layouts from scratch. Related topics: coding, css."
---

# CSS Flexbox Layout Analyzer

Explains why a Flexbox container is not producing the layout you want and returns the corrected container and item CSS as structured JSON, ready to drop into a build tool or a review comment.

## When to use

Use this skill when a Flexbox container's CSS does not produce the intended alignment or sizing and the user wants the issues and fixed CSS returned as JSON. Do not use it for layouts that need CSS Grid, step-by-step debugging with the HTML in hand, or writing new layouts from scratch.

## 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. Resolve flex-direction first and restate the desired outcome in terms of main and cross axis, so the right property is blamed.
3. Check the container properties in spec order (wrap, justify-content, align-items, align-content) and record each one that contradicts the desired outcome.
4. Check the item properties (grow, shrink, basis, min-width, auto margins) and record any that block the intended sizing.
5. Write a one-sentence issue and a one-sentence rule explanation for each gap, keeping the two arrays parallel.
6. Produce the full corrected container and item declarations and confirm the JSON parses with exactly three fields.

## Inputs

- **Flex container selector** (free text, e.g. ".toolbar")
- **Flex item selectors** (free text, e.g. ".toolbar > li")
- **Current container CSS** (longer free text)
- **Current item CSS** (longer free text)
- **Desired layout outcome** (longer free text)
- **Browser targets** (choose any: Chrome, Firefox, Safari, Edge)

## Output

A single JSON object with issues (array of strings), explanations (parallel array), and suggestedCSS (object with container and items strings holding complete corrected declarations). No prose outside the JSON.

## Prompt template

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

### CSS Flexbox Layout Analyzer

Compare this Flexbox CSS with the layout it is supposed to produce and report the gaps as JSON.

- Flex container selector: {{Flex container selector}}
- Flex item selectors: {{Flex item selectors}}
- Current container CSS: {{Current container CSS}}
- Current item CSS: {{Current item CSS}}
- Desired layout outcome: {{Desired layout outcome}}
- Browser targets: {{Browser targets}}

Work through the container properties in the order the spec resolves them: flex-direction sets the main axis, so check it first because it decides whether justify-content or align-items controls the thing the user calls "centred". Then flex-wrap, justify-content, align-items, and align-content (which only applies with multiple lines). Then the items: flex-grow, flex-shrink, flex-basis, min-width (the default min-width: auto stops items shrinking below their content and is the most common hidden cause), and margin: auto. For each gap between the current CSS and the desired outcome, state the issue in one short sentence and the rule that explains it. Include a browser note only when a target browser differs (older Safari and gap on flex containers). Return only the JSON object with three fields: "issues" (array of short strings), "explanations" (parallel array), and "suggestedCSS" (object with "container" and "items" strings containing the full corrected declarations, not a diff).

## Pitfalls

- Blaming justify-content for vertical centring in a row container, when the cross axis is controlled by align-items.
- Missing min-width: auto on items, which stops them shrinking and makes flex-shrink look broken.
- Returning a diff or partial declarations in suggestedCSS, which the user cannot paste over the original.
