Sub topic 13
Testing with Device Emulation and Real Devices
This chapter assumes you can write basic HTML and CSS, and you know how to open your browser's developer tools. It also assumes you have followed the earlier chapters: a viewport meta tag, a single-column base layout, min-width media queries, touch-friendly navigation and responsive images. Here you check that all of that works. You will use the browser's device emulation first, then real phones and tablets.
Why testing is a separate step
A mobile-first page can look correct in a desktop browser and still fail on a phone. The reasons are practical. A phone has a different pixel density, a touch screen, a slower processor, a less reliable network and browser toolbars that change size as you scroll. No single tool reproduces all of these. A good test routine uses several tools, each for what it does well.
The routine has two stages:
- Emulation in desktop browser developer tools. It is fast, free and good for layout and network behaviour.
- Real devices. They are slower to set up, but they show touch, rendering, performance and browser quirks that emulation cannot.
Device emulation in browser tools
Chrome, Edge, Firefox and Safari all include a mode that simulates a small screen. In Chrome and Edge it is the device toolbar (press Ctrl+Shift+M, or Cmd+Shift+M on macOS, with DevTools open). Firefox calls it Responsive Design Mode. Safari has a Responsive Design Mode in its Develop menu.
What emulation does
When you pick a device preset or drag the viewport edges, the tools change several things:
- The viewport width and height, so your media queries match as they would on a phone.
- The device pixel ratio, which shows whether your
srcsetchoices work. - The user agent string, which is the text a browser sends to identify itself.
- Touch input. Mouse clicks are treated as taps, and hover behaviour changes.
- Optional throttling of the network and CPU.
What to check first
Start at the narrowest width you support, such as 320 CSS pixels. Then widen the viewport slowly, and watch for the point where the layout starts to look wrong. This ties back to content-driven breakpoints. If the text lines become too long or the cards look stretched at some width, that width is a candidate for a new min-width query. Do not only test the preset device sizes, because real users have windows of every width.
Use this checklist at each width:
- Is there any horizontal scrolling? There should be none.
- Is the most important content visible without scrolling too far?
- Does the text stay readable without zooming?
- Are all links and buttons easy to hit?
- Do the images keep their shape and avoid jumping as they load?
Finding horizontal overflow
Horizontal scrolling on a phone is one of the most common mobile defects. A single element that is wider than the viewport causes it. This short script lists the elements that extend past the right edge of the viewport. Paste it into the DevTools console:
const viewportWidth = document.documentElement.clientWidth;
const overflowing = [...document.querySelectorAll("body *")].filter(
(el) => el.getBoundingClientRect().right > viewportWidth
);
console.table(
overflowing.map((el) => ({
tag: el.tagName.toLowerCase(),
className: el.className,
right: Math.round(el.getBoundingClientRect().right),
}))
);Typical causes are images without max-inline-size: 100%, long unbroken strings such as URLs, fixed-width tables, and elements with width: 100vw inside a page that also has a vertical scrollbar.
Checking the viewport meta tag
If your layout looks like a shrunken desktop page, the viewport tag is probably missing or wrong. Confirm that the document head contains this line:
<meta name="viewport" content="width=device-width, initial-scale=1">In the emulator, a missing tag usually shows up as a very wide layout scaled down, with tiny text. Be careful with one detail. Some emulators do not always reproduce the fallback layout of a real mobile browser, so a missing tag may be hidden in emulation. A real phone will expose it.
Throttling the network and CPU
Your development machine is much faster than a mid-range phone, and your office connection is faster than a mobile network. Use the throttling controls to reduce the difference:
- In the Network panel, choose a preset such as "Fast 4G" or "Slow 4G", or a custom profile.
- In the Performance panel, set CPU throttling to 4x or 6x slowdown.
- Tick "Disable cache" so that you see a first visit, not a repeat one.
Then reload and watch the page load. Ask these questions:
- Which request is the largest? If it is an image, check that
srcsetandsizesare doing their job. The Network panel shows which file the browser picked. - Does the layout jump as images arrive? Missing
widthandheightattributes are the usual cause. - Is the text visible while fonts load?
- Is the total transferred size within the budget you set?
You can also run Lighthouse from DevTools. It reports performance, accessibility and best-practice checks, and it flags problems such as small tap targets and a missing viewport tag. Treat its score as a guide to find problems. A high score does not prove the page is pleasant to use.
Testing user preferences
Emulation can also test settings that users change on their own devices. In Chrome's Rendering panel you can emulate:
prefers-color-schemefor dark mode.prefers-reduced-motionfor users who want less animation.- Print media.
If you use media queries for these, test both values.
Limits of emulation
Emulation changes the viewport size and some inputs. It does not change the browser engine or the hardware. These are the gaps that matter most:
| Area | What emulation shows | What it misses |
|---|---|---|
| Touch | Clicks treated as taps | Real finger size, accidental touches, scroll momentum, multi-touch gestures |
| Rendering | Your desktop browser's rendering | Differences in iOS Safari and Android browsers, font rendering, GPU behaviour |
| Performance | Simulated slowdown | Real memory limits, heat and battery effects, background tabs being discarded |
| Browser chrome | A fixed viewport size | Address bars that collapse as you scroll, which change the visible height |
| On-screen keyboard | Nothing | The keyboard covering form fields and resizing the visible area |
| Network | A steady throttled speed | Variable signal, packet loss and connection changes |
| Input quirks | Standard form fields | Zoom on focus in iOS Safari for inputs with small text, autofill, native pickers |
Two of these cause many bugs. The first is viewport height. Mobile browsers show and hide the address bar as you scroll, so 100vh can be taller than the visible area. Modern browsers support the dvh unit (dynamic viewport height), which follows the visible area. Use it for full-screen sections, and check the result on a real phone.
The second is form input zoom. iOS Safari zooms into an input when it receives focus if the input's font size is below 16px. Setting form controls to at least 1rem avoids this, but you will only see the problem on an iPhone.
input,
select,
textarea {
font-size: 1rem;
}
.hero {
min-block-size: 100vh;
min-block-size: 100dvh;
}The first min-block-size is a fallback for browsers that do not know dvh. Browsers ignore declarations they do not understand, so the second one replaces it where it is supported.
Testing on real devices
You do not need a large device lab. A small set that covers the main differences is enough:
- One recent iPhone (iOS Safari is the only engine on iOS in most regions, though browser behaviour differs in some places).
- One mid-range or older Android phone with Chrome. A slower phone shows performance problems that a flagship hides.
- One tablet, if your audience uses them.
If you cannot own the devices, ask colleagues or friends to test, or use a cloud testing service that provides real hardware. These services cost money, and they are slower to use than local devices, so reserve them for final checks.
Reaching your page from a phone
You need a way to open your in-development page on the phone. These are common options:
- Same Wi-Fi network. Run your dev server so that it listens on all interfaces, then open
http://YOUR-COMPUTER-IP:PORTon the phone. Most dev servers have a flag for this, and the computer's firewall must allow the connection. - A tunnel. A tunneling tool gives your local server a temporary public URL. Remember that anyone with the URL can see your work, so avoid it for private content.
- A staging site. A deployed preview is the most realistic test, because it includes real hosting, caching and HTTPS.
Some browser features, such as geolocation and service workers, require HTTPS. A plain local address may disable them, and this is a common source of confusion.
Remote debugging
Real devices can also be inspected from your computer:
- Android with Chrome. Enable developer options and USB debugging on the phone, connect it by cable, then open
chrome://inspecton your computer. You get the full DevTools for the page on the phone, including the console and network panel. - iPhone with Safari. Turn on Web Inspector in the iPhone's Safari advanced settings. On a Mac, enable the Develop menu in Safari, connect the phone, and choose it from the Develop menu.
Remote debugging lets you read console errors from the phone and measure real load times. If you do not have a Mac, you can still test on an iPhone by hand, but you will have less information about what is going wrong.
A real-device test script
Do the same short script on each device so the results are comparable:
- Open the page on a mobile network, not only on Wi-Fi.
- Rotate the device to landscape, then back.
- Scroll the whole page slowly, and watch for jumps in the layout.
- Open and close the navigation using one thumb.
- Tap each link and button. Note any missed taps or accidental taps on neighbours.
- Fill in a form. Check that the keyboard does not hide the field you are typing in, and that the right keyboard type appears for email and number fields.
- Open any
detailselement and check that it expands smoothly. - Zoom the text size up in the system settings and check that the layout still holds.
- Turn on a screen reader (VoiceOver on iOS, TalkBack on Android) and move through the main navigation.
Recording and iterating
Testing only helps if the results lead to changes. Keep a simple log of defects, with the device, the browser, the width, what you saw and what you expected. Group the defects by cause. Several of them often have one root cause, such as a missing min-width: 0 on a flex or grid child that lets long content push the layout wider.
When you fix something, test the fix at the narrowest width first, then at the width where you saw the problem, then on the real device. A fix for a larger screen can break the base layout if you did not write it inside a min-width query. This is why mobile-first order helps you: the small-screen rules come first, so they do not depend on overrides.
After each round, ask whether the findings should change your rules and not only your code. For example, if three pages failed because of unconstrained images, add a global rule that all images are limited to their container. If tap targets were often too small, add a minimum size to your shared button and link styles.
Common errors
- Testing only a few device presets and missing the widths between them.
- Treating a good Lighthouse score as proof that the page works on a real phone.
- Testing only on fast Wi-Fi with a cached page.
- Never testing in landscape.
- Forgetting that the emulator's hover state differs from real touch, so hover-only menus pass in the emulator and fail on a phone.
- Using a high-end phone as the only real device.
Exercise
Your page looks correct in Chrome's device toolbar at 375px wide. On a real iPhone, tapping an email field makes the page zoom in, and a full-height hero section is cut off at the bottom when the address bar is visible. Name the likely cause of each problem and the fix for each.
Show answer
The zoom happens because iOS Safari zooms into inputs whose font size is below 16px. Set the form controls to font-size: 1rem (at least 16px). The cut-off hero happens because 100vh can be taller than the visible area while the address bar is showing. Use min-block-size: 100dvh, with a 100vh declaration before it as a fallback. Emulation does not reproduce either problem, which is why a real-device pass is needed.
Exercise
You run the overflow script in the console at 320px and it lists a table with its right edge at 540px. Give two ways to stop the table from causing horizontal scrolling on the whole page.
Show answer
Wrap the table in a container with overflow-x: auto so that only the container scrolls and the page does not. Alternatively, restyle the table for small screens, for example by stacking each row as a block of label and value pairs, and restore the table layout inside a min-width media query. Either way, the page itself no longer scrolls sideways.