Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

Should responsive images still have width and height attributes?

Illustration without a description Illustration without a description

Responsive images should keep width and height attributes. The values describe the source image’s intrinsic dimensions, which give the browser an aspect ratio before the file downloads. The browser can reserve the correct amount of vertical space during the first layout and reduce movement when the image appears.

 

Use the pixel dimensions of the source named in src, or dimensions with the same aspect ratio as every candidate in srcset. The attributes do not lock a responsive image at that displayed size. CSS can still make the image narrower than its intrinsic width while the browser calculates a proportional height.

 

<img
src='team-1200.jpg'
srcset='team-600.jpg 600w, team-1200.jpg 1200w'
sizes='(max-width: 45rem) 100vw, 50vw'
width='1200'
height='800'
alt='Project team reviewing a site layout'>

 

Pair the attributes with responsive CSS such as max-width: 100% and height: auto. The browser maps the HTML dimensions to an aspect ratio, then CSS controls the rendered size. If CSS declares another aspect ratio for an art-directed crop, reserve that intended shape explicitly and confirm that the content still fits.

 

Candidates with different crops need more care because their aspect ratios may differ. The fallback dimensions can reserve space for the default candidate, while CSS aspect-ratio can define the component’s stable box. Use object-fit: cover only when cropping is acceptable. A mismatched ratio can cause a smaller shift after source selection.

 

Check the page with cache disabled and slow network throttling. Watch the area before and after the image loads, then inspect layout-shift records in browser performance tools. Test each art-directed source at its media condition. Correct dimensions improve stability without changing responsive selection, image sharpness or alternative text.