width and height on business website images: how to reserve space, avoid layout shift (CLS) and template mistakes

width and height on business website images: how to reserve space, avoid layout shift (CLS) and template mistakes
Published on 21/10/2026

What width and height mean on a web image

The width and height attributes on <img> describe the intrinsic pixel dimensions of the file. They do not replace CSS: the browser uses them to derive aspect ratio before the image finishes downloading, so it can reserve space on the page.

On a business website, every team photo, enlarged icon, or blog image shipped without dimensions can push text, navigation, or your contact button when it finally loads. That movement is a common driver of poor CLS (Cumulative Layout Shift) and visitors leaving before they read your offer.

Why it matters for corporate sites (not only technical blogs)

WordPress themes, Shopify sections, and visual builders often output <img src="..."> without width and height, or with thumbnail sizes that do not match the final layout. On mobile the hero “jumps”, the form shifts, and users tap the wrong link.

Reserving space with correct dimensions improves perceived quality, reduces frustration on catalog and service pages, and complements lazy loading and srcset and sizes: you can defer loading without collapsing the layout.

How aspect-ratio and modern CSS fit in

In CSS you can set aspect-ratio: 16 / 9 (or the file’s real ratio) with width: 100% and height: auto. HTML width/height remain valuable because the browser learns the ratio from the first HTML parse, even before external stylesheets apply.

Recommended pattern in 2026:

<img src="photo.jpg" width="1600" height="900" alt="..." loading="lazy" decoding="async" style="max-width:100%;height:auto;">

Values should match the real file (or the default variant you serve), not the on-screen size. CSS scales; aspect ratio prevents the jump.

Avoiding CLS without squashing images

The classic mistake is setting width/height to the container box (e.g. 400×300) when the JPEG is 4000×3000 with a different ratio. The browser reserves the wrong rectangle; when height: auto applies, the layout shifts again.

Always verify the source aspect ratio. If the CMS crops, update attributes or regenerate thumbnails. For responsive sets, use the default src variant’s dimensions in the attributes.

Developer reviewing HTML image width and height attributes on a corporate website in a laptop code editor

HTML dimensions versus CSS only

CSS-only width: 100% without HTML attributes forces the browser to wait for intrinsic height. With correct attributes, vertical space is fixed from the start—especially visible in news lists, project grids, and team pages with many photos.

If your framework injects inline styles, ensure they do not break ratio (e.g. fixed height: 200px on all thumbnails).

Practical cases on company pages

  • Service hero: width/height on the main banner; use fetchpriority only on the LCP image.
  • Client logos: reserve the same height for every logo to stop the row from “breathing” on load.
  • Landing icons: when swapping SVG for PNG, set explicit dimensions.
  • Blog content: the editor must keep attributes on publish—inspect generated HTML.

Step-by-step implementation

  1. Audit above-the-fold images with Lighthouse or PageSpeed: look for missing explicit dimensions.
  2. Read real width and height from file metadata or the CMS.
  3. Add width and height in HTML or components (React/Vue: pass them to <img>).
  4. Apply responsive CSS: max-width: 100%; height: auto; or a container with aspect-ratio.
  5. After WebP/AVIF changes, confirm the default variant keeps the same ratio.
  6. Re-check field CLS (CrUX) after a few weeks of traffic.

Common mistakes

  • Copying desktop width/height onto a mobile crop with a different aspect ratio.
  • Forgetting widget images (reviews, chat, embeds) that load without reserved space.
  • Using height: 0 padding hacks without updating when the design changes.
  • Assuming the page builder “already optimizes” without checking live HTML.

Tools and checks (2026)

Chrome DevTools → Performance recording with “Experience” to tie layout shifts to images. Search Console → Page experience when you have enough volume. HTML validators flag img elements without dimensions.

Teams with CI can lint templates to require width/height on image components.

Pre-launch checklist

  • All template images have width/height matching the file.
  • CSS does not force heights that break aspect ratio.
  • Lazy-loaded images still reserve space.
  • Lab CLS under 0.1 on key pages (home, services, contact).

Conclusion

width and height are a small code detail with a large UX impact: stable pages, more trust, and better alignment with Core Web Vitals. You do not need a redesign—just discipline when publishing images and reviewing what templates output. If you want a performance and layout audit on your corporate site, aatsoft can prioritize high-converting pages and apply these fixes without sacrificing brand design.

Àlex
Àlex
CEO & Full Stack Developer

More from the blog

Contact us

Reach out through your preferred channel and we will get back to you as soon as possible.

Contact us