Home / Fix guides / Mobile and usability

Images overflowing the screen on mobile: how to fix it

An image runs off the edge of a phone screen when it has a fixed width wider than the screen. Setting max-width: 100%; height: auto; on images, and removing fixed pixel widths, fixes it in most cases.

When an image is wider than a phone screen, it either gets cut off at the edge or it makes the whole page wider, so visitors have to swipe sideways to see everything. In most cases the cause is an image with a fixed width, and the fix is a small piece of CSS plus a check that the page tells phones how to size it.

What people see

The signs are easy to spot once you know them:

  • A photo or banner runs off the right edge and the end of it is cut off
  • The page can be dragged left and right, with empty white space on one side
  • Text looks tiny because the phone zooms out to fit the too-wide content
  • Buttons or text near the image sit partly off screen

Why it matters

Google mainly uses the mobile version of your pages to index them, so a broken mobile layout is the version it judges. Sideways scrolling and zoomed-out text also make a business look unfinished, which costs trust. And if a visitor cannot see the full product photo or the button next to it, they are less likely to buy or get in touch.

How to check for free

  1. Open the page on your own phone and try swiping sideways. Rotate the phone too, since some problems only show in one direction.
  2. On a computer, open the page in Chrome, press F12 (or right click and choose Inspect), then click the device icon (Toggle device toolbar). Pick a phone, or set the width to around 375 pixels. Firefox has a similar Responsive Design Mode (Ctrl+Shift+M).
  3. To find the culprit, open the Console tab and paste this. It lists every image that reaches past the edge of the screen:
document.querySelectorAll('img').forEach(i => { if (i.getBoundingClientRect().right > document.documentElement.clientWidth) console.log(i); })
  1. Right click the image, choose Inspect, and look in the Styles panel for a width set in pixels, on the image or on the box around it.

How to fix it in general

Work through these in order. Step 2 alone is often enough.

  1. Check the viewport tag. Inside the <head> of the page there should be <meta name="viewport" content="width=device-width, initial-scale=1">. Without it, phones pretend the screen is desktop sized and shrink everything.
  2. Make images flexible. Add this to your stylesheet:
img { max-width: 100%; height: auto; }

This means an image is never wider than the space it sits in, and its height follows so it is not squashed. Most modern themes already include it, so if your images still overflow, something else is overriding it, such as custom CSS or a page builder setting.

  1. Remove fixed sizes in the page itself. Look for style="width: 800px" or a pixel width on the image or on the container around it. Replace it with a percentage or a max-width. Plain width and height attributes on an image are fine as long as the rule above is in place, and they help the browser reserve space while the image loads.
  2. Check background images and other wide elements. A banner set as a background needs a container without a fixed pixel width and usually background-size: cover or contain. Sometimes the image is innocent and the real culprit is an embedded video, map, table or iframe. If the whole page scrolls sideways, see horizontal scroll on mobile.
  3. Send right-sized files. A phone does not need a photo 4000 pixels wide. Resize large images before uploading, or use srcset and sizes so the browser picks a suitable file. Many platforms do this for you. Smaller files also load faster.

One shortcut to avoid is overflow-x: hidden on the page. It hides the sideways scrolling but the image is still cut off, and it can cause odd side effects such as broken sticky headers.

Common platforms

Menu names differ between versions and themes, so treat these as pointers for where to look.

  • WordPress: the theme usually handles image sizing. Overflow tends to come from images pasted into a Custom HTML block or the classic editor with a fixed width, or from a plugin's CSS. You can test the rule above in Appearance, Customize, Additional CSS. See the WordPress guide.
  • Shopify: check custom sections, and images pasted into rich text with a fixed width. Theme settings are under Online Store, Themes, Customize. See the Shopify guide.
  • Wix, Squarespace and Webflow: these builders resize images for you, so the cause is usually a code embed or an element given a fixed pixel width. In Webflow, check the width of the element at the mobile breakpoints in the Designer.
  • Elementor and WooCommerce: in Elementor, switch the editor to mobile view and check the width of the image widget and its section. In WooCommerce, product galleries come from your theme, so look at the theme's settings and any custom CSS first.

How to confirm the fix worked

Clear any caching plugin or site cache first, then reload in a private window so you see the new version. Check the page in device mode at a few narrow widths (for example 320 and 390 pixels), in portrait and landscape. Run the console snippet again and make sure it lists nothing. Finally, try it on a real phone, because that is what your visitors use.

How to stop it coming back

  • Upload pictures through your normal media library or editor rather than pasting HTML with fixed widths.
  • Keep the max-width: 100% rule in your theme or main stylesheet, not only on one page.
  • After a theme change, plugin update or new landing page, look at it on a phone before telling anyone.
  • Resize very large photos before uploading them.
  • SiteMonday's week 5 mobile usability test checks how your pages behave on phones and puts problems like this on a ranked fix list. Fixing them is still up to you or your developer.

Step by step for your platform

Questions

Why does only one image overflow on my phone?

That image probably has a fixed width set directly on it or its container, or it was added through a custom HTML block. The other images follow the theme's rules, which already keep them inside the screen.

Is `max-width: 100%` enough on its own?

Often yes, but not if a container around the image has a fixed pixel width or the page has no viewport tag. In that case the image shrinks to a box that is itself too wide.

Will `overflow-x: hidden` fix it?

It hides the sideways scroll but does not fix the image, which is still cut off. It can also break things like sticky headers, so use it only as a last resort.

Does this affect my Google ranking?

Google mainly looks at the mobile version of your pages, so a broken mobile layout is what it sees. It also makes the page harder to use, which can cost you enquiries and sales.

Why does it look fine on my computer?

Wide screens have room for a fixed-width image, so the problem only appears once the window is narrower than the image. Narrowing your browser window, or using the browser's device mode, shows it.

Do I need a developer?

Often not. If you can edit your theme's custom CSS or fix an image's width in the editor, you can do it yourself. A developer helps when the cause is deep in a theme or page builder.

Related problems