To make a website fit on all devices, you set one responsive viewport tag in the HTML head, build layouts that shrink and reflow instead of assuming a fixed screen width, and let text and images scale within their containers. The key condition is that responsiveness is a design habit, not a single line of code: the viewport tag unlocks correct mobile scaling, but fluid widths, flexible media, and sensible breakpoints do the real work. The steps below are ordered so you can apply them to a new page or retrofit an existing one, with checks after each stage so a fix in one place never breaks another.
Start with the viewport and document baseline
Everything else depends on the browser knowing it should map CSS pixels to the device width rather than pretending to be a desktop monitor. Without this, mobile browsers zoom out and your carefully sized layout renders as a tiny desktop page.
Put this in the of every page:
width=device-width tells the browser to use the device's actual width as the layout viewport. initial-scale=1 sets the initial zoom to 1:1. Do not add maximum-scale=1 or user-scalable=no to "lock" zoom; that harms accessibility by preventing users who need magnification from pinching to zoom. Those attributes are the most common self-inflicted failure on otherwise responsive sites.
Also add a correct character set and a sane base:
Success check: open the page in a desktop browser's device emulation, pick a small phone preset, and confirm text is readable without horizontal scrolling. If the page looks zoomed out and tiny, the viewport tag is missing, duplicated, or overridden by a conflicting tag.
Make width fluid instead of fixed
The single biggest cause of "doesn't fit" is fixed pixel widths. A width: 960px container will overflow any screen narrower than 960 CSS pixels. Replace fixed widths with relative ones.
Use this default for structural blocks:
The pattern width: 100%; max-width: 1100px means "be as wide as the screen, but never wider than 1100px on large displays." The box-sizing: border-box reset prevents padding from adding to declared widths, which otherwise causes overflow when you add inner spacing. max-width: 100% on images stops them from spilling out of their parent; height: auto preserves aspect ratio.
A concrete before-and-after: a card with width: 350px; padding: 20px; total 390px and overflows a 360px phone. With box-sizing: border-box; width: 100%; max-width: 350px; it fits and stays comfortable.
Success check: temporarily set the browser window very narrow (about 320px) and confirm no element pushes the page wider than the screen. A quick diagnostic is to add * { outline: 1px solid red; } temporarily to spot the overflowing element visually.
Choose a layout model that reflows
Fixed floats and absolute positioning are brittle across widths. Two modern tools handle most reflow needs: Flexbox for one-dimensional rows and columns, and CSS Grid for two-dimensional arrangements with auto-fit or minmax().
For a set of cards that should form columns on wide screens and stack on narrow ones, Grid's intrinsic sizing does the work without breakpoints:
This says: fit as many columns as possible that are at least 240px wide, and let them grow to fill the row. On a 320px screen you get one column; on a 1200px screen, four or five. For navigation or a header that should sit in a row on desktop and stack on mobile:
flex-wrap: wrap is the key: when items run out of room, they wrap to the next line rather than forcing overflow.
Success check: resize continuously from wide to narrow and watch items reflow rather than get clipped. If something stays cut off, it probably has a fixed width or white-space: nowrap you need to revisit.
Scale type and spacing fluidly
Text that is too small to read or headings that break lines badly are a fit problem too. A common, low-risk technique is clamp() for fluid typography:
clamp(min, preferred, max) keeps the size between a floor and ceiling while scaling with viewport width (vw). This avoids both unreadable tiny headlines on phones and oversized ones on desktops. Keep a minimum body size around 16px for readability, and avoid setting vw-only font sizes, which can become unreadably small or enormous at extremes.
For spacing, a simple scale using rem plus padding that grows modestly works better than fixed pixel gaps:
Success check: read a paragraph on the narrowest and widest emulated devices. If lines run edge to edge or the type is uncomfortably small, adjust the clamp bounds. Aim for roughly 45–75 characters per line on larger screens.
Add breakpoints only where content breaks
Breakpoints are not about matching specific phone models; they are about where your content stops working. Test by narrowing the window until something looks wrong, then add a media query there.
Use min-width queries for a mobile-first cascade: write base styles for narrow screens, then enhance as space grows. This tends to produce leaner CSS than desktop-first max-width overrides. Rely on Grid's auto-fit and flex wrap for as much as possible, and reserve explicit breakpoints for cases where the design genuinely changes (for example, moving a sidebar beside content or switching a nav into a horizontal bar).
Success check: keep a running list of the widths where you added queries, then jump to each minus and plus a few pixels to confirm the switch happens cleanly with no overlap or gap.
Handle media, tables, and forms
Images: pair max-width: 100%; height: auto with correct width and height attributes on the element so the browser reserves space and avoids layout shift. For art direction, the element lets you serve different crops at different widths:
Tables are a classic overflow culprit. Wrapping a wide table in a scroll container keeps the page fitting while letting the table scroll horizontally:
Forms: inputs with a fixed width: 300px overflow small screens. Use width: 100% and max-width together, and set font-size: 16px or larger on inputs to prevent automatic zoom on iOS when a field is focused.
Success check: confirm images don't stretch or pixelate, wide tables scroll inside their wrapper rather than breaking the page, and form fields are comfortably tappable at phone width.
Account for touch targets and interaction
Fit isn't only visual. On a touchscreen, small tap targets cause mis-taps and frustration. Give interactive elements at least about 44×44 CSS pixels of tappable area, including icons and close buttons, typically by padding the element rather than enlarging the glyph.
Use hover-independent states. Hover-only menus that reveal on :hover may be unusable on touch devices. Either duplicate the interaction for focus and tap, or reveal content by default on small screens. Avoid relying on position: fixed bars that cover content on short landscape screens; test landscape phone orientation specifically.
Success check: try to complete the primary action (open a menu, submit a form) using only taps in emulation, and confirm nothing requires hovering and no control is smaller than a fingertip.
Test, diagnose, and fix overflow
Testing is the part people skip. Do it systematically:
1: Use the browser's responsive design mode to step through widths from about 320px to 1440px and watch for overflow or awkward text wrapping. 2: Check real-ish device presets, including a small phone, a large phone, a tablet in both orientations, and a laptop. 3: Run an accessibility check for contrast, focus visibility, and zoom support. 4: Validate HTML and check that there is exactly one viewport meta tag.
When you find horizontal scrolling, diagnose the cause rather than guessing. A reliable trick is to temporarily apply outline: 1px solid red to all elements, then narrow the window; the element that sticks out past the edge is the culprit. Common causes, from most to least frequent: a fixed pixel width, a long unbreakable string (URLs, code), a large image or embed, negative margins, or absolutely positioned elements outside a relatively positioned parent.
Long unbreakable content can be tamed with overflow-wrap: anywhere or word-break: break-word on the relevant container, but use these sparingly, since they can break normal words in odd places.
Success check: no horizontal scrollbar at any tested width, all text readable, primary actions reachable by tap, and no layout shift on load.
Stop condition: if you need to support very old browsers that lack Flexbox or Grid, or you are integrating a third-party widget you cannot restyle, the fix may require either a graceful-degradation fallback or a framework-level change. At that point, a front-end specialist or the widget vendor is the right resource rather than unbounded CSS hacks.
What "fitting" does and doesn't guarantee
Responsive fitting solves layout across screen widths, but it is not the same as performance, accessibility, or full cross-browser correctness. A page that technically fits can still load a 4MB hero image and frustrate mobile users, or fail keyboard navigation. Keep the priorities separate: first make it fit and reflow, then optimize images with srcset and sizes, lazy-load below-the-fold media, and verify accessibility. Also remember that fitting is tested against CSS pixel widths, and device pixel ratios (two or three physical pixels per CSS pixel) affect sharpness, not layout, so use higher-resolution images via srcset rather than scaling down one large image by guesswork.
Finally, treat responsiveness as maintenance. New content — a pasted table, a long headline, a newly embedded video — is the usual reason a once-fitting site starts overflowing. Build a habit of testing at narrow widths whenever you add content, and the page will keep fitting across devices without a rescue effort.
FAQ
Do I need a CSS framework to make a site fit on all devices?
No. The viewport tag plus fluid widths, flexible media, and Grid or Flexbox cover the overwhelming majority of cases. Frameworks can speed things up and provide tested breakpoints, but they are not required and can add weight if only a small subset is used. The principles above apply whether or not you use one.
Why does my site still look tiny on a phone even with the viewport tag?
Usually a duplicate or conflicting viewport tag, a maximum-scale/user-scalable=no lock, or a page mode that ignores the tag (for example, some email clients and in-app browsers render differently). Check for multiple viewport tags first, then confirm no single fixed-width container is forcing a desktop-like layout.
What is the minimum viewport width I should design for?
Design down to about 320 CSS pixels of usable width, which is near the low end of small phones. Testing at 320px catches most overflow problems; you don't need to enumerate every device model. From there, test upward at several breakpoints and in landscape orientation.