Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Audit a Web Page at 320px for Horizontal Overflow

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Auditing a web page at 320px wide checks whether any content forces the page to scroll sideways on small phones. Horizontal overflow is a common responsive design bug that makes elements cut off or creates an awkward sideways scroll. This guide shows you how to detect and fix it using browser developer tools, no extra software needed.

What You'll Need

  • A computer with a modern browser (Chrome, Firefox, Edge, or Safari).
  • The URL of the page you want to test.
  • Basic familiarity with browser DevTools (opening them and clicking around).

Step-by-Step

  1. Open the page in your browser. Navigate to the URL you want to audit. Make sure you are testing the live version, not a cached copy—do a hard refresh (Ctrl+Shift+R on Windows/Linux, Cmd+Shift+R on Mac) if needed.
  2. Open Developer Tools. Right-click anywhere on the page and select “Inspect” (or press F12 / Cmd+Option+I). This opens the DevTools panel.
  3. Enable device toolbar. In DevTools, click the device icon (a small rectangle with a phone outline) in the top-left corner of the panel, or press Ctrl+Shift+M (Cmd+Shift+M on Mac). This switches to responsive design mode.
  4. Set the viewport to 320px. At the top of the page, you’ll see a toolbar with a width and height field. Click the width field and type 320. The height can be anything (e.g., 800). Press Enter. The page will re-render at that width.
  5. Check for horizontal scroll. Look at the bottom of the page—if a horizontal scrollbar appears (even a thin one), you have overflow. Alternatively, you can use the console to check: type document.documentElement.scrollWidth > document.documentElement.clientWidth and press Enter. If it returns true, there is overflow.
  6. Find the offending element. In the console, run this script to highlight elements that extend beyond the viewport:
    document.querySelectorAll('*').forEach(el => {
      const rect = el.getBoundingClientRect();
      if (rect.right > window.innerWidth || rect.left < 0) {
        el.style.outline = '2px solid red';
      }
    });
    This outlines every element that goes outside the 320px width in red.
  7. Inspect the red-outlined elements. Hover over each red outline in the page. The DevTools Elements panel will highlight the corresponding HTML. Click on it to see its CSS rules.
  8. Identify the cause. Common culprits include:
    • Fixed-width elements (e.g., width: 400px).
    • Large images or videos with intrinsic width.
    • Margins or padding that push content beyond the viewport.
    • Long unbreakable text (e.g., URLs, code) that doesn't wrap.
    • CSS grid or flexbox items with min-width or min-content that exceed 320px.
  9. Fix the issue. Adjust the CSS to make the element responsive. For example:
    • Change fixed widths to max-width: 100%.
    • Add overflow-wrap: break-word to text containers.
    • Set images to max-width: 100%; height: auto;.
    • Remove or reduce margins/padding on small screens.
    • Use min-width: 0 on flex/grid children to allow them to shrink.
  10. Re-test. After making changes, refresh the page and repeat steps 5–7 to confirm the overflow is gone.

Common Mistakes

  • Only checking the top of the page. Overflow can happen anywhere, especially in footers or hidden elements. Always scroll down and test the entire page.
  • Forgetting to reset zoom. If your browser zoom is not at 100%, the viewport width might not be accurate. Ensure zoom is set to 100%.
  • Testing only one breakpoint. While 320px is the narrowest common width, also test at 375px (iPhone SE) and 414px (iPhone 11) to catch other issues.
  • Ignoring the scrollbar width. On desktop, scrollbars take up space, but on mobile they don't. The 320px viewport in DevTools simulates a mobile device, so it's accurate.
  • Assuming it's a CSS framework issue. Sometimes overflow is caused by a plugin or third-party widget. Use the outline script to find the exact element, not just the container.

Tips

  • Use the scrollWidth check in the console as a quick pass/fail test—it’s faster than visually scanning.
  • In the outline script, you can change outline to border if you want to see the element's exact boundaries.
  • If the overflow is caused by a third-party script (like a map or ad), consider wrapping it in a container with overflow-x: hidden as a temporary fix, but better to fix the source.
  • Test with real mobile devices if possible, as some rendering nuances (like font loading) differ.
  • Use the “Device Toolbar” to simulate touch events and see if the issue only happens on certain interactions.

Troubleshooting

  • No horizontal scrollbar appears, but the console says overflow. This can happen if an element is positioned off-screen (e.g., position: absolute; left: 100%). Use the outline script to find it and adjust its position.
  • The outline script doesn't highlight anything. Make sure you ran the script after the page loaded. If the page has dynamic content, re-run it after interactions. Also, check if the overflow is on the html or body element itself—use document.querySelector('html') and document.querySelector('body') in the console to inspect them.
  • Overflow only appears after scrolling. This suggests a lazy-loaded image or a sticky element. Scroll to the bottom and re-run the outline script.
  • Fixed elements cause overflow. A fixed element with width: 100% might still overflow if it has padding or borders. Use box-sizing: border-box to include padding in the width.
  • Overflow is in a modal or popup. Open the modal and then re-run the audit. The script will highlight elements inside the modal.

Frequently Asked Questions

Why is 320px the standard width to test?

320px is the width of the smallest common smartphone (iPhone 5/SE, many Android devices). If your site works at 320px, it will work on almost all mobile devices.

Can I use this method on a live site without access to the code?

Yes, you can use the DevTools to inspect and even edit CSS locally, but changes won't be permanent. For a full fix, you'll need access to the source files.

What if the overflow is caused by a third-party widget I can't change?

Wrap the widget in a container with overflow-x: hidden to prevent it from breaking the layout, but be aware this might hide content. Better to contact the widget provider.

Does this test work for RTL (right-to-left) pages?

Yes, but the overflow may occur on the left side. Adjust the outline script to check rect.left < 0 as well, which it already does.

How do I check for overflow in Safari?

Safari's DevTools are similar. Open Develop menu, enable “Show Develop menu” in Preferences, then use the same steps. The outline script works in Safari's console too.

Should I also test at 280px?

280px is the width of very small devices like the Galaxy Fold. If your target audience includes such devices, test there too, but 320px covers the vast majority.