Responsive Design for AI Coders
Make your website look great on every screen size, from phones to ultrawide monitors.
In this chapter
- Why your site looks broken on phones and how to fix it
- What breakpoints are and which ones to use
- How to describe responsive layouts to your AI tool
- The mobile-first mindset every AI coder should adopt
Breakpoints
Breakpoints are the screen sizes where your layout adapts. Your website layout can change at these common screen sizes:
Mobile-First Approach
Common Responsive Patterns
Responsive Navigation
How to Test Responsive Design
Mobile vs Desktop: Side by Side
See how the same content rearranges itself on different screen sizes. On a phone, everything stacks vertically. On desktop, elements spread out.
Common Breakpoints
These are the standard screen widths where your layout should adapt. Think of them as "checkpoints" where your design shifts to fit the screen.
Why Mobile-First?
Most visitors will see your site on a phone first. If it looks great on a small screen, it will look even better when there is more room.
The idea is simple:
- Start with the phone layout. Everything in a single column, simple and readable.
- At the "md" breakpoint (768px), switch to 2 columns where it makes sense.
- At the "lg" breakpoint (1024px), expand to 3 or more columns, add sidebars, and use the extra space.
Responsive Images
Images that are too wide will break your layout on phones. A responsive image shrinks and grows with its container, so it always fits the screen.
Three rules for responsive images
- Max width 100%: Tell the image to never be wider than its container. This one rule prevents most overflow issues.
- Keep the aspect ratio: When an image shrinks, it should stay in proportion (no stretching or squishing). Modern browsers do this automatically.
- Lazy loading: Tell images below the fold (not visible when the page first loads) to load only when the visitor scrolls to them. This makes your page load faster.
Touch vs Click
Phone users tap with their fingers, not a precise mouse pointer. Designing for touch means making buttons big enough to tap comfortably.
Key differences between touch and mouse
- Bigger tap targets: Buttons, links, and form fields need to be at least 44px tall on mobile. Fingers are much bigger than mouse cursors.
- No hover on touch: Phones don't have a hover state. If important info only appears when you hover, phone users will never see it. Use tap or always-visible alternatives.
- Swipe gestures: Phone users expect to swipe through image carousels and dismiss things by swiping. If you have a carousel or gallery, make sure it supports swipe.
- Spacing between links: Put enough space between tappable items so users don't accidentally tap the wrong one.
Testing Your Responsive Design
You built it, now make sure it looks good everywhere. Here is the quickest way to check.
Using Chrome DevTools (free, built into your browser)
- Open your site in Google Chrome.
- Right-click anywhere on the page and choose "Inspect" (or press F12).
- Click the device icon in the top-left of the panel (looks like a phone and tablet). You can also press Ctrl+Shift+M (Windows) or Cmd+Shift+M (Mac).
- Pick a device from the dropdown (iPhone, iPad, etc.) or drag the handles to resize freely.
- Check each breakpoint: make the screen narrow, then gradually wider, and watch your layout change.
βThis component looks good on desktop but breaks on mobile. Make it fully responsive: stack elements vertically on phones, use 2 columns on tablets, and keep the current layout on desktop. Make sure all buttons are at least 44px tall on mobile, images scale properly, and nothing overflows the screen.β
Prompt This
Copy-paste these prompts into your AI tool to apply what you just learned.
βMake my page fully responsive. On mobile, stack everything vertically with full-width sections. On tablet, use a 2-column grid where it makes sense. On desktop, use the full layout with sidebar. Make sure text is readable and buttons are tappable at every size.β
βMy website looks broken on mobile. Fix the layout so all content is readable, buttons are large enough to tap, images scale down properly, and nothing overflows or gets cut off on small screens.β
βMake my navigation responsive. On desktop, show all links in a horizontal row. On mobile, collapse the links into a hamburger menu that opens a dropdown or slide-in drawer. Add smooth transitions when opening and closing.β
Frequently Asked Questions
What screen sizes should I design for?
Focus on three: mobile (375px), tablet (768px), and desktop (1280px). Tailwind's default breakpoints (sm, md, lg, xl) cover these well. Always design mobile-first: start with the phone layout and add complexity for larger screens.
Why does my site look different on my phone vs my computer?
Phones have smaller screens and different pixel densities. If you haven't added responsive styles, your desktop layout gets squished on mobile. Tell your AI tool to make every component responsive. It will add the right breakpoints automatically.
What does 'mobile-first' mean?
It means you design for phone screens first, then add styles for larger screens. In Tailwind, unprefixed classes apply to all screens, and prefixed classes (sm:, md:, lg:) add styles at larger sizes. This approach ensures your site always works on the smallest screens.