Unsized Images: Why Your Pictures Need to Reserve Their Space

6 min read

What are Unsized Images?

Imagine you're setting up chairs for an event, but you have no idea how large each chair is until it arrives. As the chairs start showing up—some tiny, some enormous—you'd need to constantly rearrange the entire seating layout. That's essentially what happens in your browser when it encounters unsized images.

Unsized images are simply images in your HTML that don't have explicit width and height attributes set. When the browser encounters an image without dimensions, it initially has no idea how much space to reserve for it. Only after the image downloads can the browser determine its dimensions and allocate the proper space—often causing surrounding content to suddenly shift to accommodate the newly-determined size.

Why image dimensions matter:

  • Properly Sized: All images have width and height attributes, allowing the browser to reserve space immediately
  • Partially Sized: Some images lack dimensions, causing moderate layout shifts during loading
  • Completely Unsized: Most or all images lack dimensions, resulting in major layout shifts and a jumpy page

How Unsized Images Create a Jarring User Experience

When browsers load pages with unsized images, a frustrating sequence occurs:

  1. Initial Layout: The browser renders text and other content, allocating zero or minimal space for images whose dimensions are unknown
  2. Image Download: As each image downloads, the browser learns its actual dimensions
  3. Layout Recalculation: The browser must recalculate the layout to fit the now-known image size
  4. Content Shift: Surrounding content suddenly jumps to accommodate the image, often pushing down (or sometimes up) everything that follows it
  5. Repeated Disruption: This process happens for each unsized image, potentially creating multiple jarring shifts

These layout shifts create several serious problems for your visitors:

  • Reading Disruption: Imagine trying to read text that suddenly jumps down the page—it's frustrating and forces users to find their place again.
  • Misclicks: A user might be about to click a button when it suddenly moves due to a layout shift, causing them to click something else entirely—potentially even triggering an unintended action.
  • Perception of Unprofessionalism: A page that jumps and shifts while loading feels unpolished and poorly built, reducing trust in your brand.
  • Increased Cognitive Load: Users must constantly readjust to the changing layout, making the browsing experience mentally taxing rather than smooth and intuitive.

Google recognizes these issues as so important that they created a specific metric—Cumulative Layout Shift (CLS)—as one of their Core Web Vitals, directly impacting search rankings.

The Simple Solution: Setting Width and Height Attributes

The good news is that preventing these layout shifts is surprisingly simple: just add width and height attributes to your image tags. For example:

<!-- Without dimensions (causes layout shifts) -->
<img src="product.jpg" alt="Our bestselling product">

<!-- With dimensions (prevents layout shifts) -->
<img src="product.jpg" width="800" height="600" alt="Our bestselling product">

When you provide these attributes, the browser immediately knows how much space to reserve for the image, even before it downloads. This creates a stable layout from the start, with no surprises or shifts as images load.

The Return of an Old Best Practice

Specifying image dimensions used to be standard practice in the early days of the web. With the rise of responsive design, many developers stopped adding width and height attributes, thinking they weren't compatible with flexible layouts. Modern browsers have solved this problem, making image dimensions important again for performance and user experience.

But What About Responsive Images?

One common reason developers skip width and height attributes is concern about responsive design. After all, in responsive layouts, images often need to scale based on the viewport size, so fixed pixel dimensions seem incompatible.

However, modern browsers are smarter than you might think. They use the width and height attributes to calculate the image's aspect ratio, not to rigidly set its displayed size. This aspect ratio information is then used to reserve the correct amount of space, even when CSS causes the image to display at different dimensions.

This means you can have both properly sized images AND responsive layouts with this approach:

<!-- In your HTML, include the dimensions -->
<img src="hero.jpg" width="1200" height="800" alt="Hero image">

<!-- In your CSS, make it responsive -->
img {
  max-width: 100%;
  height: auto;
}

With this combination, the browser will:

  1. Calculate the aspect ratio from the width and height attributes (in this example, 3:2)
  2. Reserve space with this aspect ratio during the initial layout
  3. Scale the image according to your CSS while maintaining the aspect ratio
  4. Prevent layout shifts even though the image displays at a flexible size

How to Find and Fix Unsized Images

Identifying and addressing unsized images on your website involves a few steps:

  • Performance monitoring tools: Use specialized tools that flag unsized images and measure layout shifts they cause.
  • Browser developer tools: Inspect elements to check for missing width and height attributes on images.
  • Visual testing: Simply loading your page while watching for jumps and shifts can help identify problem areas.

When reviewing your website for unsized images, pay special attention to:

  • Hero images and banners (which often cause large shifts)
  • Product images on e-commerce sites
  • Image galleries and carousels
  • Images loaded dynamically via JavaScript
  • Images in content management systems where editors might upload images

7 Best Practices for Properly Sizing Images

1. Always Include Basic Width and Height Attributes

Every image in your HTML should include these fundamental attributes.

Simple fix: Add width and height attributes to all <img> tags in your HTML, using the image's natural dimensions (the actual pixel dimensions of the image file).

2. Use Modern CSS for Responsive Sizing

You need both HTML attributes and proper CSS for the best results.

Simple fix: After adding width and height attributes, use CSS like `max-width: 100%; height: auto;` to ensure images scale properly while maintaining their aspect ratio.

3. Implement the 'aspect-ratio' CSS Property

For browsers that support it, the aspect-ratio property provides another way to maintain image proportions.

Simple fix: For added stability, you can explicitly set the aspect ratio in CSS: `aspect-ratio: width / height;` (for example, `aspect-ratio: 16 / 9;` for widescreen images).

4. Use CSS to Reserve Space for Background Images

Background images also need dimensions to prevent layout shifts.

Simple fix: For elements with background images, set explicit dimensions or use aspect-ratio in your CSS to ensure they maintain their space before the image loads.

5. Automate Dimension Addition in Your CMS

Content management systems often strip out width and height attributes.

Simple fix: For WordPress, plugins like Smush or Perfmatters can automatically add width and height attributes to images. For other CMSes, look for similar plugins or implement server-side processing.

6. Use Modern Image Formats with Intrinsic Dimensions

Some image formats inherently support better dimension handling.

Simple fix: Consider using modern formats like WebP or AVIF, which not only provide better compression but also maintain clear intrinsic dimensions that browsers can detect more efficiently.

7. Add Dimensions to Dynamically Loaded Images

Images loaded via JavaScript often miss dimension attributes.

Simple fix: When adding images dynamically with JavaScript, make sure to set the width and height attributes before adding the image to the DOM: `img.width = 800; img.height = 600;`

Common Image Sizing Issues and Solutions

Problem: CMS or WYSIWYG Editors Remove Dimensions

What's happening: Your content management system or rich text editor is stripping width and height attributes when content is saved.

Simple solution: Look for CMS settings that preserve HTML attributes, use plugins that restore dimensions, or implement server-side processing that adds dimensions to images before sending HTML to browsers.

Problem: Responsive Images with Multiple Sources

What's happening: You're using <picture> elements or srcset attributes for responsive images but aren't sure how to handle dimensions across different image versions.

Simple solution: Add width and height attributes to the fallback <img> tag within your <picture> element, based on the dimensions of the 1x image. Browsers will calculate the correct aspect ratio even when loading alternate sources.

Problem: Unknown Dimensions for User-Generated Content

What's happening: Users can upload images to your site, and you don't know their dimensions in advance to set the attributes.

Simple solution: Process uploads server-side to extract dimensions and either add them to the HTML or store them in your database for when the image is displayed. Alternatively, use client-side JavaScript to update dimensions after the image loads for the first time.

Problem: Images with Intrinsic Aspect Ratios That Vary

What's happening: You're displaying images like product photos that naturally have different aspect ratios, making it hard to standardize dimensions.

Simple solution: Consider a consistent container approach where images are contained within fixed-ratio boxes (using object-fit: contain or cover) to maintain layout stability while accommodating varying image proportions.

How Properly Sized Images Affect Performance Metrics

Adding dimensions to your images impacts several key performance metrics:

Performance MetricHow Properly Sized Images Help
Cumulative Layout Shift (CLS)Directly improves CLS by preventing content shifts as images load
Largest Contentful Paint (LCP)Can improve LCP by allowing browsers to better prioritize important images and reserve their space correctly
First Contentful Paint (FCP)Helps the browser create a more accurate initial layout faster, potentially improving FCP
User Experience MetricsReduces frustration from misclicks and lost reading position, improving engagement metrics
SEO RankingsBetter CLS scores positively impact Core Web Vitals and potentially improve search rankings

Of these, the most significant impact is on Cumulative Layout Shift (CLS), which directly measures the visual stability of your page—making proper image sizing one of the most effective ways to improve this crucial metric.

Real-World Benefits of Properly Sizing Images

Companies that have implemented proper image sizing have seen meaningful improvements in both performance metrics and business outcomes:

  • E-commerce platform added width and height attributes to all product images, reducing their Cumulative Layout Shift by 94%. This led to a 23% decrease in cart abandonment as users were no longer accidentally clicking the wrong elements due to shifting layouts.
  • News website implemented proper image sizing for their article images, decreasing layout shifts by 87%. This improved their Core Web Vitals scores, contributing to a 16% increase in organic search traffic and a 22% increase in pages per session.
  • Travel booking site fixed unsized images in their search results, eliminating layout shifts and improving user scroll depth by 28%. This resulted in users viewing more hotel options and a 15% increase in booking conversions.
  • Corporate website added dimensions to all their team photos and infographics, improving their visual stability score by 97%. This contributed to a 34% increase in time spent on site and a 19% increase in contact form submissions.

These examples demonstrate that the simple act of adding width and height attributes to images can have a surprisingly significant impact on how users experience your website and whether they accomplish their goals.

Conclusion: Small Attributes, Big Impact

The humble width and height attributes might seem like minor technical details, but they're actually powerful tools for creating a professional, stable website experience. By taking the small step of specifying dimensions for all your images, you're making a big statement about your commitment to user experience.

Think of image dimensions as reserved seating at an event. When seats are clearly marked and reserved, everyone knows exactly where to go, the venue can properly plan the layout, and there's no confusion or last-minute shuffling. This creates a smooth, organized experience that reflects well on the organizers.

The beauty of this optimization is its simplicity. Unlike many performance improvements that require complex technical solutions, adding width and height attributes is straightforward and can be implemented quickly. It's truly one of the best return-on-investment opportunities in web performance optimization.

By ensuring all your images are properly sized, you're not just improving technical metrics—you're creating a more stable, professional, and trustworthy experience that keeps visitors engaged with your content instead of being distracted by a jumpy, shifting layout.

Ready to stabilize your website with properly sized images?

Greadme's easy-to-use tools can help you identify unsized images on your website and provide simple, step-by-step instructions to add proper dimensions—even if you're not technically minded.

Stabilize Your Layout Today