Responsive design makes one web page adapt to available space, input methods, zoom levels, orientation and user preferences. Build a flexible HTML and CSS foundation first, then add media queries only where the content needs a different arrangement. This approach works better than maintaining separate “phone,” “tablet” and “desktop” templates.
MDN Web Docs defines it this way: “Responsive design refers to a site or application design that responds to the environment in which it is viewed.”
Start with a flexible document
Responsive behavior begins in the document, not in a list of device widths. Use semantic elements so the page has a meaningful structure at every size.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="site-header">
<a class="brand" href="/">Acme Docs</a>
<nav aria-label="Primary navigation">
<a href="/guides">Guides</a>
<a href="/reference">Reference</a>
<a href="/about">About</a>
</nav>
</header>
<main class="layout">
<article>
<h1>Responsive layout</h1>
<p>Content can reflow, wrap and resize without horizontal scrolling.</p>
</article>
<aside>Related guides</aside>
</main>
</body>
</html>
Normal HTML text already reflows. Problems usually come from fixed widths, long unbreakable strings, oversized media or absolute positioning that assumes one viewport.
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
The viewport declaration
Keep <meta name="viewport" content="width=device-width, initial-scale=1"> in the document head. Without it, some mobile browsers use a wide virtual layout viewport; narrow-screen media queries may then appear not to work as expected.
Build a fluid base layout
Use percentages, flexible tracks and minimum or maximum constraints instead of a page-wide fixed width.
* { box-sizing: border-box; }
body {
margin: 0;
color: #202124;
background: #fff;
font: 1rem/1.6 system-ui, sans-serif;
}
.site-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 1rem clamp(1rem, 4vw, 3rem);
}
.site-header nav {
display: flex;
flex-wrap: wrap;
gap: .75rem 1.25rem;
}
.layout {
width: min(100% - 2rem, 72rem);
margin-inline: auto;
display: grid;
grid-template-columns: minmax(0, 2fr) minmax(12rem, 1fr);
gap: clamp(1.5rem, 4vw, 4rem);
padding-block: clamp(2rem, 6vw, 5rem);
}
article { min-width: 0; }
img, video, svg {
display: block;
max-width: 100%;
height: auto;
}
h1 { font-size: clamp(2rem, 5vw, 4rem); }
minmax(0, ...) prevents a grid item’s intrinsic content from forcing overflow. clamp() lets spacing and type scale between a lower and upper bound. The min-width: 0 rule is particularly useful for long code, URLs and headlines inside grid or flex items.
Choose Grid or Flexbox before adding breakpoints
Flexbox for one-dimensional groups
Flexbox is suited to a row or column of items, such as navigation, a button group or a card’s internal alignment. Allow items to wrap and use a flexible basis.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →.cards {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.card {
flex: 1 1 16rem;
min-width: 0;
}
Cards expand when there is room and move to additional lines when there is not. No breakpoint is required for that behavior.
Grid for two-dimensional structure
Grid expresses rows and columns together. An auto-fitting card grid can adapt to available space:
.product-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
gap: 1rem;
}
Use a media query when the content needs a structural change, such as moving a sidebar below an article or changing a navigation pattern. Do not add one merely because a device is marketed as a tablet or phone.
Write content-led media queries
A breakpoint is the point where the current presentation stops working. Resize the page until a navigation row wraps awkwardly, a paragraph becomes too wide or two columns become cramped; place the query near that point. Relative units such as rem and em make the rule less tied to a particular pixel density or user font size.
Recommended Free Tools
/* Base layout: narrow and wide screens both work */
.layout {
grid-template-columns: 1fr;
}
/* Change only when the content has enough room */
@media (min-width: 50rem) {
.layout {
grid-template-columns: minmax(0, 2fr) minmax(14rem, 1fr);
}
}
@media (min-width: 50rem) {
.site-header nav {
justify-content: flex-end;
}
}
Mobile-first CSS is a useful default: write the simplest readable arrangement first and layer enhancements at larger widths. There is no universal “correct” breakpoint; the correct value depends on your content, type scale and controls.
Queries for conditions other than width
Media queries can react to orientation, print, pointer capabilities and user preferences.
Rank #3
@media (orientation: landscape) and (max-height: 35rem) {
.hero { min-height: 0; }
}
@media print {
nav, .no-print { display: none; }
a { color: #000; text-decoration: none; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .01ms !important;
animation-iteration-count: 1 !important;
transition-duration: .01ms !important;
scroll-behavior: auto !important;
}
}
@media (prefers-reduced-data: reduce) {
.background-video { display: none; }
}
Feature availability varies by browser, so check support before relying on a newer media feature in a critical interaction.
Make media and components resilient
- Set
max-width: 100%on replaced elements and give images meaningfulalttext. - Use responsive image sources when file size matters:
srcsetandsizeslet the browser select an appropriate resource. - Keep embedded maps, tables and code blocks from creating page-wide overflow. Wrap them in an element with intentional horizontal scrolling when necessary.
- Use
aspect-ratiofor reserved media space where browser support meets your project’s requirements, and provide a fallback if it is essential. - Prefer intrinsic sizing over JavaScript that reads the viewport for ordinary layout. CSS can reflow more reliably when zoom changes.
Accessibility is part of responsiveness
A layout that fits a narrow viewport can still fail users who zoom, navigate by keyboard or use a screen reader.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →- Preserve a logical source order. Visual rearrangement with
orderor grid placement must not make keyboard navigation or reading order confusing. - Do not disable zoom with restrictive viewport settings. Text and controls should remain usable when enlarged.
- Keep tap and click targets comfortably separated, with visible focus styles.
- Do not communicate essential information by color alone, and maintain readable contrast at every theme or background.
- Use headings, landmarks, labels and button elements according to their meaning rather than styling generic containers.
Responsive design supports accessibility, but it does not replace semantic HTML, keyboard testing or assistive-technology checks.
Test around the points where the layout changes
- Open the page in a browser and resize the viewport continuously from narrow to wide.
- Record the width where each component becomes cramped, then inspect several pixels below and above that point.
- Use the browser’s responsive-design tools to simulate viewport sizes, orientation and device pixel ratio. This checks layout behavior; it is not a substitute for testing on physical hardware.
- Zoom the page and increase the default font size. Look for clipped text, overlapping controls and unexpected horizontal scrolling.
- Tab through every interactive element and confirm that focus follows the reading order.
- Test print output if the page is intended for paper or PDF, and test reduced-motion preferences when animations exist.
Troubleshoot common failures
There is horizontal scrolling
Inspect the widest element in the browser’s layout panel. Common causes are a fixed pixel width, an image without a max-width, a long URL, a grid item missing min-width: 0 or a flex child that cannot shrink. Fix the offending component rather than hiding overflow on the entire page.
The media query never applies on mobile
Check the viewport meta element first. Then verify that the stylesheet loaded, the selector is not overridden by later rules, and the query’s unit and condition are correct.
Rank #4
The layout breaks when text is enlarged
Replace fixed heights with minimum heights, allow wrapping, use relative units and test at increased zoom. Avoid placing text in background images.
A two-column layout is unreadable
Measure the content, not the device. Reduce the number of columns or stack the regions when line lengths, controls or navigation become cramped.
Images cause layout shifts
Declare intrinsic dimensions or an aspect ratio, use appropriately sized sources and avoid loading a full desktop image into a small slot.
Performance and maintainability choices
- Keep the base rules simple and let Grid or Flexbox perform the reflow instead of duplicating markup for each device class.
- Group media queries by component or concern so a later change does not create contradictory overrides.
- Use a small set of design tokens for spacing, color and type, expressed with custom properties and relative units.
- Reserve large media space, defer noncritical resources where appropriate and avoid layout scripts that run on every resize event.
- Document why a breakpoint exists (“navigation labels no longer fit”), not just its numeric value.
Or skip the browser setup
If you need screenshots of your responsive states for documentation, regression checks or sharing, ScreenshotNeo can capture the page through one HTTP request. It accepts consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before the capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status.
For a basic capture, see the ScreenshotNeo API documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
It also offers full-page and element captures, device presets or custom viewports, retina scale, dark mode, custom CSS and JavaScript, selector waits, network-idle waits, request blocking, headers, cookies, geolocation, PDF output, caching, signed links, asynchronous webhooks and bulk capture of up to 100 URLs per call. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.
Best Value
The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to capture your responsive layouts.
Frequently Asked Questions
Do I need a media query for every component?
No. Flexbox, Grid, intrinsic sizing, wrapping and fluid functions often adapt without a breakpoint. Add a query when the component needs a different arrangement or must respond to print, orientation or a user preference.
Should breakpoints match common phone and tablet widths?
Use the width at which your content stops working, preferably expressed with relative units. Device labels are less reliable than observing your own navigation, text and controls.
Free tools Windows power users keep installed
One-click scans. No signup required.
Is browser responsive mode the same as testing a real phone?
No. Browser tools simulate viewport conditions and help verify layout behavior. Physical devices can reveal differences in touch input, browser UI, performance, fonts and rendering.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




