How To Fix WordPress Mobile Image Alignment & Text Wrap Problems

Left- and right-aligned images look beautiful on desktop browsers, but sometimes with responsive WordPress themes you end up with something like this:

Yuck.

Because of the skinny portrait-style image, the text is wrapping improperly on mobile, and it looks like a mess.

Very frustrating, but with a couple of lines of CSS, we can clear this right up.

The approach I’ve found most effective is to automatically center your left- and right-aligned images on smaller screens.

To do this, open up the stylesheet for your child theme, or the Custom CSS section of the theme Customizer, and drop in the following code:

@media only screen and (max-width: 600px) {
 figure.alignleft, img.alignleft, figure.alignright, img.alignright {
 float:none;
 display:block;
 margin-left:auto;
 margin-right:auto;
    }
}

The logic here is simple: on screens with a width less than 600 pixels, images aligned to the right or left (via WordPress’s default style classes) will be centered via float:none, margin-left:auto, and margin-right:auto. (Feel free to modify the max width to suit your needs.)

The result? The image in the example above now appears centered on smartphones, but still perfectly right-aligned on larger screens:

Much better!

I hope this helps! If you have any questions, please feel free to leave them in the comments below.

Brad Merrill

Brad Merrill is the CEO of Merrill Media and Editor in Chief of GigaPress.

View Comments

  • Christie Bellah says:

    Worked great - what a nice, quick fix. Thank you!!

  • I'm facing an issue with WordPress mobile images alignment and text wrap problems after an auto updates on theme my website http://www.bsventures.in could any one help me to fix this issue.

  • It worked! Sorry was viewing outdated version of my blog.

  • Not working for me. I added to my theme custom css, but still text are wrapping.

  • Maxine MacDonald says:

    Thank you so much for this! It's helped me greatly!

    • Brad Merrill says:

      No problem! Glad it helped! :)

  • Many thanks for this code, it certainly helped.

    In my case 1 problem remains:
    The images that have captions are not affected by it and remain aligned with default settings. Is there any way I can fix this please?

    Thanks again!

  • stephanie khan says:

    You did it!!!! You Rock! Thank you!

    • Brad Merrill says:

      Awesome, glad to help!!

  • Chris Duke says:

    Holy cow... thank you. I can't believe how well this worked and how simple it was to implement. A virtual high-five! 🖐

    • Brad Merrill says:

      No problem Chris, glad to hear it helped you out! 🖐

  • CJ Roberts says:

    Thanks for the snippet. This should really be the default behavior.

    • Brad Merrill says:

      I agree! Some themes handle it better than others.

  • This did exactly what I needed, thanks so much

    • Brad Merrill says:

      No problem!

Recent Posts

Is Wix a WordPress Site? Understanding the Difference

If you’re exploring website builders, you may wonder, “Is Wix a WordPress site?” or even,…

16 hours ago

How to Get to WordPress Dashboard:Quick Access Guide

Are you missing out on the full power of your WordPress site because you’re not…

3 days ago

How to Add Facebook Pixel to WordPress Site: (Easiest Way)

Are you looking to track visitors on your WordPress website, optimize ad performance, and increase…

1 week ago

Is WordPress Easy to Use for Beginners? A Comprehensive Guide

If you’re wondering, “Is WordPress easy to use?” you’re not alone. Many beginners want a…

2 weeks ago

How to Add Shortcode in WordPress: A Beginner-Friendly Tutorial

Shortcodes are an essential part of WordPress. Allowing users to quickly add dynamic content to…

2 weeks ago

How to Embed Facebook Video in WordPress: A Comprehensive Walkthrough

Learning how to embed Facebook video in WordPress can take your site’s content to the…

3 weeks ago