Skip to main content

Claude Prompt to Build Responsive CSS Layouts

Build production-ready responsive CSS layouts with semantic HTML, mobile-first breakpoints, container queries, dark mode and zero layout shift.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build a responsive dashboard with sidebar, header, main content, and widget grid layout using Tailwind CSS with CSS Grid and Flexbox.

Layout requirements:
Collapsible sidebar (240px expanded, 64px collapsed), sticky header, 3-column widget grid that stacks on mobile, scrollable main area

Breakpoints:
- Mobile: <640px (single column, no sidebar)
- Tablet: 640-1024px (collapsed sidebar, 2-col grid)
- Desktop: >1024px (full sidebar, 3-col grid)

Constraints:
- Framework: Tailwind CSS 3.4
- Browser support: last 2 versions of Chrome, Firefox, Safari, Edge
- Must pass Core Web Vitals (no layout shift)

Provide:
1. **HTML structure** — semantic, accessible markup
2. **CSS/Tailwind** — mobile-first responsive styles
3. **Layout behavior at each breakpoint** — describe what changes
4. **Edge cases** — handling overflow, long content, missing content, RTL support
5. **Container queries** — use where appropriate for component-level responsiveness
6. **Animation** — subtle transitions between breakpoints
7. **Dark mode** — color adjustments
8. **Performance** — no CLS, efficient selectors, minimal reflows

Test scenarios:
- Minimum content (empty states)
- Maximum content (overflow handling)
- Dynamic content (items added/removed)

Output production-ready code, not a tutorial.

What this prompt does

This prompt drives an AI assistant to produce a complete, deployment-ready responsive layout rather than a teaching example. The template forces you to specify your exact CSS approach (pure CSS, Tailwind, CSS Modules), your three breakpoints, and your browser support floor upfront — so the output matches your actual project constraints instead of some generic tutorial baseline.

The eight required output sections work together. Asking for CLS handling, edge cases, and container queries in the same request means the AI cannot stop at the happy path. You get overflow handling, empty states, and RTL support as part of the first response, not as follow-up patches.

The "production-ready code, not a tutorial" instruction at the end is load-bearing. It signals to the model to suppress explanatory prose and inline comments teaching basics, keeping the output dense and immediately usable.

When to use it

  • You are building a card grid that needs to reflow from 1 to 2 to 4 columns without cumulative layout shift on page load.
  • You need a sidebar + content layout that collapses to a stacked mobile view and you want the container query version, not a viewport-width hack.
  • You are migrating a legacy float-based layout to modern CSS Grid and need a tested, accessible structure fast.
  • Your design system requires dark mode support and you want the color token logic baked into the layout CSS from the start.
  • You are prototyping a dashboard with dynamic content (rows added via Livewire or React) and need overflow and minimum-content states handled.
  • You are targeting a specific browser support floor (say, Safari 16+) and need to know which CSS features are safe without a polyfill.

Example output

For layout_type: "product card grid", css_approach: "CSS Grid + custom properties", mobile_bp: 320px, tablet_bp: 768px, desktop_bp: 1280px, framework: "none", browser_support: "last 2 versions":

/* Mobile-first grid */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  container-type: inline-size;
}

@media (min-width: 768px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1280px) {
  .card-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Container query: card reflows when its container is narrow */
@container (max-width: 300px) {
  .card__meta { flex-direction: column; }
}

/* Subtle breakpoint transition — no layout-triggering properties */
.card {
  transition: box-shadow 0.2s ease;
}

@media (prefers-color-scheme: dark) {
  .card-grid { --card-bg: #1e1e2e; --card-border: #2e2e4e; }
}

The AI also returns the matching semantic HTML, breakpoint-by-breakpoint behavior notes, and RTL-safe logical property variants (margin-inline-start instead of margin-left) for the edge-cases section.

Pro tips

  • Set browser_support precisely. "Modern browsers" gives the AI permission to use features you cannot ship. "last 2 Chrome/Firefox/Safari versions, no IE" produces tighter, more accurate code.
  • Use css_approach: "Tailwind" only if your project already has Tailwind configured. Mixing Tailwind utilities with arbitrary @apply in a non-Tailwind project creates build errors the AI will not warn you about.
  • The container query output is opt-in. If your layout is page-level (viewport-driven), explicitly note "no nested contexts" in layout_description so the AI does not add container queries where they add no value.
  • Pair this prompt with a real CLS audit. Run Lighthouse after pasting the output. The prompt requests CLS-safe code but the AI cannot measure your actual font loading or image dimensions — those are your responsibility.
  • For RTL support, add dir="rtl" to your layout_description. The prompt already asks for RTL edge cases, but it needs to know your text direction to generate logical properties (margin-inline-start vs margin-left) correctly.

Frequently Asked Questions

Does this prompt work if I am using Tailwind CSS instead of vanilla CSS?
Yes. Set `css_approach` to "Tailwind" and `framework` to your Tailwind version (e.g., "Tailwind CSS v3"). The AI will output utility classes and a `tailwind.config.js` `screens` extension for custom breakpoints instead of raw CSS. If you need both — utility classes for spacing and a custom CSS Grid for the layout skeleton — specify that explicitly in `layout_description`.
Will the output actually pass Core Web Vitals, or is that just a claim?
The prompt instructs the AI to avoid layout shift and inefficient selectors, but it cannot measure your page. What you get is CSS structured to avoid common layout-shift causes: sizes declared on grid and flex containers, transitions that animate non-layout properties like `box-shadow` and `opacity`, and logical properties that do not flip unexpectedly on direction change. CLS from your own font loading, lazy-loaded images, or JavaScript-injected content is outside what this prompt controls — audit those separately with Lighthouse.
How do I handle a layout that has completely different structure on mobile vs desktop, not just reordered columns?
Describe the two structures separately in `layout_description`. For example: "Mobile: single-column stacked nav + content + footer. Desktop: fixed left sidebar (240px) + scrollable main + sticky right panel." The AI will use CSS Grid template areas or a Flexbox + Grid combination to produce genuinely different layouts without changing DOM order, keeping accessibility and focus order intact across breakpoints.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Frontend Development Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support