Warning: Constant WP_CACHE already defined in /home/u194588600/domains/concepttoweb.com/public_html/wp-config.php on line 3

Warning: Constant WP_DEBUG already defined in /home/u194588600/domains/concepttoweb.com/public_html/wp-config.php on line 101
Smart Thumbnails with "object-fit" | Concept to Web | Surprise, AZ Web Design, Development, and SEO

Smart Thumbnails with “object-fit”

So you’ve built a perfect grid with perfectly sized product thumbnail images, perhaps in a squared size, but whenever the client uploads images with an incorrect size, they will be squished into the rectangle, potentially being incorrectly resized. You could avoid resizing issues with background-size, but what if you have to deal with good ol’ source images?

We can use object-fit to achieve just that. object-fit: contain; “letterboxes” the images, preserving their aspect ratio. Alternatively, object-fit: cover; has the same effect as background-size: cover;, with every pixel in the element filled with the image, and the “leftovers” on each side cropped out.

Finally, object-fit: none; leaves the images at its original size and correct aspect ratio, but focuses at its center, with overflow cropped. Just one thing to keep in mind: for object-fit to work, we need to define both width and height of the box. The property is supported in Chrome, Safari, Opera and Android, and is coming to Firefox soon. You can also use a polyfill to make it work in legacy browsers.

Thank you to Smashing Magazine for this article and idea.

    Comments are closed

    Concept To Web designs clean, budget-friendly websites that are simple to update. If you’d rather not lift a finger, we can handle maintenance too.
    Proudly Serving West Valley Small Businesses in Surprise, Peoria, Glendale, Goodyear, Avondale, Verrado, Buckeye, Sun City, and Waddell, AZ
    © 2025 Concept To Web. All Rights Reserved.