---
name: css-flexbox-layout-debugger
description: "Walks through an alignment problem in a Flexbox layout with the markup in hand, checking the usual suspects in order until the cause is found, and gives the CSS change that fixes it. Use when a Flexbox layout is misaligned, overflows, or wraps unexpectedly and the user has the HTML and CSS ready to paste. Do not use for generating a new Flexbox layout, analysing CSS without the markup, or converting a layout to Grid. Related topics: coding, css."
---

# CSS Flexbox Layout Debugger

Walks through an alignment problem in a Flexbox layout with the markup in hand, checking the usual suspects in order until the cause is found, and gives the CSS change that fixes it.

## When to use

Use this skill when a Flexbox layout is misaligned, overflows, or wraps unexpectedly and the user has the HTML and CSS ready to paste. Do not use it for generating a new Flexbox layout, analysing CSS without the markup, or converting a layout to Grid.

## 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. Inspect the HTML for structural causes first: wrong container, wrapper elements, non-direct children, and stray whitespace nodes.
3. Run the property checklist in order (display, direction, axis, wrap, item sizing, margins, parent sizing, browser quirks) and stop at the first check that explains the symptom.
4. Write one bullet per relevant check with what the snippet shows and the exact selector and declaration to change when it is the cause.
5. Give the final minimal CSS to apply and one sentence on verifying it in DevTools.

## Inputs

- **HTML snippet** (longer free text)
- **CSS snippet** (longer free text)
- **Flex container selector** (free text, e.g. ".card-row")
- **Problem description** (free text, e.g. "the last item drops to a new line on tablet")
- **Desired outcome** (choose one: Space between, Centered, Equal width, Wrapped, Single line, Pinned to the end)
- **Target browsers** (choose any: Chrome, Firefox, Safari, Edge, Opera)

## Output

A Markdown section titled Debugging Checklist: ordered bullets, each with the check, the finding, and the CSS fix when it applies, followed by a fenced block of the final declarations and a one-line verification note.

## Prompt template

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

### CSS Flexbox Layout Debugger

Find out why this Flexbox layout misbehaves and give me the fix.

- HTML snippet: {{HTML snippet}}
- CSS snippet: {{CSS snippet}}
- Flex container selector: {{Flex container selector}}
- Problem description: {{Problem description}}
- Desired outcome: {{Desired outcome}}
- Target browsers: {{Target browsers}}

Read the HTML before the CSS: whitespace text nodes, a wrapper element the CSS does not target, or an item that is not a direct child explain more bugs than any property does. Then follow the checklist in order and stop at the first item that explains the symptom: is display: flex on the right element; is flex-direction what the user assumes; does the intended property act on the main or cross axis; is wrap set when items overflow; do items have min-width: auto or a fixed width that fights flex-shrink; is a margin or padding breaking equal widths; is a percentage height or width missing a sized parent; does a target browser handle gap or flex-basis differently. For each item that is relevant write one bullet: the check, what you found in the snippet, and the exact CSS change (selector and declaration) if it is the cause. Finish with the minimal full set of declarations to apply and one sentence on how to confirm the fix in DevTools.

## Pitfalls

- Jumping to CSS when the real cause is markup, such as the items not being direct children of the flex container.
- Prescribing justify-content: center for a vertical problem in a row container; the axis decides which property applies.
- Setting a fixed width on items to force equal columns, which breaks the moment content or viewport changes; flex: 1 1 0 is the fix.
