🧠 All Things AI
Beginner

Responsive Layouts with AI

AI generates responsive CSS and Tailwind layouts quickly, but the output quality depends entirely on how well you describe the layout at each breakpoint. A vague prompt yields generic responsive boilerplate; a specific description of what changes at which viewport width yields immediately usable code. This page covers how to describe layouts precisely, how to choose between Flexbox and Grid, and how to debug responsive issues with AI help.

Mobile-First Layout Prompts

Describe the layout at mobile first, then describe exactly what changes at each wider breakpoint. "Make it responsive" tells AI nothing about your design intent.

Write mobile-first [CSS / Tailwind CSS] for the following layout.

Framework: [REACT / HTML / Next.js / Vue]

CSS approach: [Tailwind v4 / plain CSS with custom properties / CSS Modules / styled-components]

Layout description:

Mobile (default): [DESCRIBE — e.g., "single column, full width. Header at top. Below: content area. Below: sidebar stacked below content."]

Tablet (768px and up): [DESCRIBE CHANGES — e.g., "sidebar moves to the right, 280px wide. Content fills remaining space."]

Desktop (1024px and up): [DESCRIBE CHANGES — e.g., "max-width 1200px, centred. Sidebar stays right. Header gains a top navigation bar."]

Constraints:

- [e.g., "Sidebar must always be visible on tablet and up — no hamburger menu on tablet"]

- [e.g., "Content area must have minimum 16px horizontal padding at all breakpoints"]

After the code, explain why you chose Flexbox vs Grid for each layout section.

The Flexbox vs Grid explanation forces AI to justify its choices, making it easier for you to override specific decisions without rewriting the whole layout.

Flexbox vs Grid: When to Ask AI Which

Use caseBetter fitReason
Navigation bar (horizontal items)FlexboxOne-dimensional; items need to space or wrap along one axis
Card grid (equal-size tiles)GridTwo-dimensional; rows and columns align across items
Sidebar + content layoutGridNamed grid areas make the layout declaration self-documenting
Button group (variable-width items)FlexboxItems size to their content; no column alignment needed
Form layout (label + input pairs)GridLabels align across rows; grid-template-columns handles widths
Centring a single elementEitherFlexbox: container display:flex + justify-content + align-items; Grid: place-items:center

Should I use Flexbox or CSS Grid for the following layout? Explain the trade-offs for my specific case, then write the code using whichever you recommend.

[DESCRIBE THE LAYOUT IN DETAIL]

If Grid: use named grid areas so the layout intent is clear in the CSS.

If Flexbox: use flex-grow/flex-shrink values instead of fixed widths where possible.

The named grid areas instruction significantly improves Grid code readability — the template string makes the visual layout legible in CSS.

Debugging Responsive Issues

Describe the bug with specificity: which viewport size, which element, what you expect vs what happens. Paste the relevant CSS rather than asking AI to guess.

I have a responsive layout bug. Help me diagnose it.

Problem: [DESCRIBE EXACTLY — e.g., "at 768px viewport width, the sidebar overlaps the main content instead of sitting beside it. At 1024px it works correctly."]

Browser: [BROWSER AND VERSION — some bugs are browser-specific]

Relevant HTML:

[PASTE STRUCTURE]

Relevant CSS:

[PASTE CSS]

For the diagnosis: identify the specific property causing the issue, explain why it produces this behaviour at 768px specifically, and provide the corrected CSS.

Specifying the exact viewport width where the bug appears is critical — it tells AI where in the breakpoint range to look. "On mobile" is too vague.

Container Queries (2025)

Container queries are now baseline-supported across all major browsers (Chrome, Firefox, Safari). They let components respond to their container width rather than the viewport — the right tool for component libraries and reusable UI.

Rewrite this component to use CSS container queries instead of media queries. The component should respond to its container width, not the viewport.

[PASTE COMPONENT WITH MEDIA QUERIES]

Breakpoints I want:

- Narrow container (below 400px): [DESCRIBE LAYOUT]

- Wide container (400px and up): [DESCRIBE LAYOUT]

After the code, explain when I should prefer container queries over media queries for this specific component.

Container queries are preferable for any component that appears in multiple layout contexts (sidebar, main content, modal). Media queries are still correct for page-level breakpoints.

Checklist: Do You Understand This?

  • Why does "make it responsive" produce poor AI output — what do you need to provide instead?
  • What does mobile-first mean in CSS terms — what is the implication for your media query order?
  • When should you use CSS Grid instead of Flexbox — give two concrete use cases?
  • What information must you include when asking AI to debug a responsive layout bug?
  • What is a container query and when is it preferable to a media query?
  • Write a responsive layout prompt for a product card that shows image-above-text on mobile and image-left-text-right on desktop.