Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Give every ordinary <img> its real width and height attributes, then make it fluid with max-width: 100%; height: auto;. The attributes tell the browser the image’s intrinsic aspect ratio before the file arrives, while the CSS lets it shrink with its container. If the design deliberately uses a different box ratio or crop, reserve that box with CSS aspect-ratio and choose object-fit behavior deliberately.

Why images cause layout shifts

When a page contains an image without dimensions, the browser may initially lay out the surrounding text, buttons, or other controls without reserving the image’s eventual height. Once the image downloads and its dimensions become known, the browser inserts the missing space. Content below moves, producing a visible jump and contributing to Cumulative Layout Shift (CLS).

The problem is not limited to slow connections. A fast page can still shift if the first layout occurs before an image’s intrinsic size is available, if an image is injected after load, or if a responsive source changes the displayed ratio. The same kind of movement can come from video, advertisements, embeds, web-font swaps, and JavaScript-inserted content, but images are a frequent and straightforward source to eliminate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

web.dev reports that 66% of pages have at least one unsized image. The practical fix is to communicate the intended ratio up front instead of waiting for the image response.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

The standard responsive-image pattern

Use the source image’s actual pixel dimensions in HTML. Those numbers are an aspect-ratio hint; they do not force the image to render at that fixed size.

<img src="flower.jpg" width="640" height="480" alt="A flower">

The values describe a 4:3 ratio. Add fluid sizing so the image fits narrower containers:

img {
  max-width: 100%;
  height: auto;
}

At a container width of 320 pixels, the browser can render the image at 320 by 240 pixels while preserving the 4:3 ratio. At a wider viewport it can grow, subject to other layout constraints, without distorting or reserving an unrelated amount of space.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use dimensions that match the selected source

Do not use convenient placeholder numbers such as 1000 by 1000 unless the image or intended presentation is actually square. The ratio in the attributes should match the file the browser will display, or the deliberate ratio of the selected presentation. A mismatch can reserve too much or too little space, causing a second adjustment when the image is laid out.

  • Read the intrinsic width and height from the image metadata or your asset pipeline.
  • Keep the ratio consistent when multiple responsive files show the same composition.
  • If a source is cropped for a particular viewport, describe that crop’s ratio instead of the uncropped desktop asset.
  • When an editorial image is replaced, update its dimensions rather than retaining the old asset’s values.

Why the attributes still matter when CSS controls size

CSS determines the final rendered width, but the HTML attributes give the browser information during the earliest layout calculations. They are not an instruction to display every image at 640 pixels wide. With max-width: 100% and height: auto, the image remains responsive while the browser can reserve proportional space before download completion.

Use both attributes. Relying only on CSS rules such as width: 100% does not necessarily provide the intrinsic ratio early enough, and setting only one HTML dimension can allow the other dimension to be calculated incorrectly.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

When CSS aspect-ratio is the better tool

Use aspect-ratio when the design owns the box ratio. This is common for card grids, video-like thumbnails, hero slots, and components that intentionally crop source images. It is also useful for a non-image container whose content arrives later.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
img.card-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

This reserves a 16:9 box at every width. object-fit: cover scales the image until the box is filled and crops the portions that do not fit. Cropping is a design choice, not a universal replacement for intrinsic dimensions. If the entire image must remain visible, use object-fit: contain and provide an intentional background or letterboxing treatment.

Match the ratio to the visual contract

  • Use intrinsic HTML dimensions when the complete source image should remain visible and its ratio is stable.
  • Use a CSS ratio with cover when every card or slot must have the same shape and cropping is acceptable.
  • Use a CSS ratio with contain when the box is fixed but cutting off the subject would be unacceptable.

If the chosen ratio differs from the source and you omit an appropriate object-fit value, the image may be distorted or the component may not fill as intended. Decide the behavior at the same time you decide the ratio.

Responsive images and art direction

Responsive images can change both resolution and composition. A srcset set that contains differently sized versions of the same crop can share one ratio. Art direction is different: a <picture> breakpoint may select a portrait crop for a narrow viewport and a landscape crop for a wide one.

Reserve space for the presentation that will actually be selected. Modern Chrome, Firefox, and Safari support width and height on <source> elements inside <picture>, allowing each art-directed source to communicate its own ratio.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<picture>
  <source media="(max-width: 600px)" srcset="flower-portrait.jpg" width="480" height="640">
  <source media="(min-width: 601px)" srcset="flower-landscape.jpg" width="960" height="540">
  <img src="flower-landscape.jpg" width="960" height="540" alt="A flower in a garden">
</picture>

The exact values must come from the actual portrait and landscape assets. If every source has the same crop ratio, put the matching dimensions on the fallback <img> and keep the source set consistent. If source ratios differ, test each breakpoint while the page is loading so the reserved box matches the selected image.

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

A step-by-step implementation workflow

  1. Inventory images that participate in layout. Include content images, thumbnails, avatars, logos, recommendation cards, and images inserted by components. Decorative images that are permanently removed from layout with CSS still deserve review if their containers affect flow.
  2. Record the intended presentation. For a full image, use its intrinsic ratio. For a fixed card or hero slot, document the design ratio and whether the image is cropped or contained.
  3. Add both HTML dimensions. Put numeric width and height attributes on each ordinary <img>. Use the dimensions of the selected source, not arbitrary display dimensions.
  4. Apply fluid CSS where appropriate. A general rule such as max-width: 100%; height: auto; keeps the image within its container and preserves its ratio.
  5. Define deliberate crops with aspect-ratio. Set the box ratio, then select object-fit: cover or contain according to the design.
  6. Handle responsive sources. Check every <source> crop in a <picture> element and ensure its dimensions describe the presentation selected at that breakpoint.
  7. Load the page under constrained conditions. Use a throttled connection and a cold cache so you can see whether text or controls move before images arrive.
  8. Measure both lab and field behavior. Run Lighthouse after the change, then use real-user monitoring when movement occurs only on particular devices, viewport sizes, sessions, or post-load interactions.

Patterns for common image components

Article or documentation images

Use the image’s intrinsic dimensions and the fluid rule. This preserves the complete illustration and avoids imposing a card ratio on diagrams, screenshots, and photographs whose composition matters.

<figure>
  <img src="diagram.png" width="1200" height="800" alt="Request flow diagram">
  <figcaption>Request flow through the service.</figcaption>
</figure>
figure img {
  display: block;
  max-width: 100%;
  height: auto;
}

display: block is optional for layout-shift prevention, but it removes the inline-image baseline gap that can otherwise create a small amount of unexpected space.

Uniform cards and product grids

Cards generally need equal heights even when source images have different ratios. Reserve the card’s design ratio and crop consistently:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.card-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

Keep important subjects inside a safe area because cover can cut edges at some widths. If cropping would remove essential information, normalize the source assets before delivery or use contain instead.

Avatars and icons

For a circular avatar, a square ratio is part of the component contract:

.avatar {
  width: 3rem;
  height: 3rem;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 50%;
}

When the size is fixed and both CSS dimensions are present, the layout already reserves the box. Still provide accurate HTML dimensions when the element is an <img>; this keeps intrinsic sizing correct if the component becomes fluid later.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Images added by JavaScript

Set dimensions before attaching an image to the document. Creating an empty <img>, appending it, and only then assigning its source can expose a zero-height slot to the first layout.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const image = new Image();
image.width = 640;
image.height = 480;
image.alt = "A flower";
image.src = "flower.jpg";
container.append(image);

If the dimensions are not known until an API response arrives, reserve the component’s intended ratio or a defensible minimum height before inserting the content. Replace the placeholder only within that reserved box.

Lazy loading does not replace dimensions

Native lazy loading can postpone off-screen image downloads, but postponing the request does not reserve space. An image lower on the page still needs dimensions or a ratio before the user scrolls to it. Add loading="lazy" only when it fits the loading strategy; keep width, height, or aspect-ratio regardless.

<img src="gallery-1.jpg" width="1200" height="800" loading="eager" alt="Mountain trail">

Do not lazy-load the main above-the-fold image merely to hide a sizing issue. The layout reservation and the loading priority solve different problems.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When the image ratio is unavailable

Some systems receive user uploads, remote media, or generated URLs without dimensions in the initial response. You still need a stable box strategy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Store width and height with the asset record when the upload is processed.
  • Return dimensions in the API payload so the client can set them before insertion.
  • Use a component-specific aspect-ratio when the design defines a known presentation.
  • Use a conservative minimum height for late content when no exact ratio can be established, then avoid changing the surrounding flow after insertion.

A generic ratio is not automatically correct. A wrong reservation can be as disruptive as no reservation if the final image forces a substantial correction.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Diagnosing a shift that remains

Inspect the loading sequence

Open the page with a cold cache and network throttling. Watch the boundary between the image and the following content. If the boundary moves when the image decodes, inspect the element’s HTML dimensions, computed aspect-ratio, CSS width, and the actual source ratio.

Check for ratio mismatches

  • The HTML says 640 by 480, but the selected file is a different crop.
  • A <picture> source changes composition at a breakpoint without corresponding dimensions.
  • A CSS aspect-ratio reserves 16:9 while the component is later forced to a different height.
  • object-fit: cover is missing, so the image’s intrinsic size changes the box rather than filling the intended crop.

Look beyond images

If the image box remains fixed but text still moves, investigate other layout participants. web.dev identifies video, advertisements, embeds, font swaps, and content inserted after initial layout as additional CLS sources. Reserve space for those elements with known dimensions, an appropriate ratio, or a minimum height before they load.

Compare lab and field results

Lighthouse provides a controlled lab view, but a page’s full field CLS can differ because real users have different viewport sizes, network conditions, interactions, and late content. If the issue appears only in production, inspect field monitoring by URL, device class, viewport, and session timing rather than assuming the lab run represents every experience.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common mistakes and their fixes

Mistake Why it fails Fix
Using only width: 100% The browser may not know the height early enough to reserve the correct space. Add accurate HTML width and height, then keep height: auto.
Setting arbitrary HTML dimensions An incorrect ratio reserves the wrong height and can cause another adjustment. Use the selected source’s dimensions or the deliberate display ratio.
Forcing a crop without a ratio Cards can change height as intrinsic images arrive. Set aspect-ratio and choose object-fit.
Assuming lazy loading reserves space Lazy loading delays the request but does not define the layout box. Keep dimensions or an aspect ratio on lazy-loaded images.
Fixing images but ignoring late content Ads, embeds, fonts, or scripts can still move everything below them. Reserve space for every dynamic component, not just images.
Testing only with a warm cache Cached images hide movement that first-time visitors see. Test cold-cache, throttled loads and verify with field data.

Choosing between HTML dimensions and CSS aspect ratio

Technique Best fit Behavior Primary caution
HTML width and height Known source ratio and complete-image display Provides an intrinsic ratio hint while CSS can scale the image fluidly Values must match the selected source or intended presentation
CSS aspect-ratio Design-controlled box, deliberate crop, or non-image container Reserves a specified ratio independent of the source’s intrinsic dimensions Pair with suitable object-fit when source and box ratios differ

These techniques can be combined. For example, an image can carry accurate intrinsic dimensions for fallback behavior while a card class applies a 16:9 design ratio and object-fit: cover. The CSS ratio then governs the component’s visual contract, and the attributes remain truthful about the asset.

A practical review checklist

  • Does every layout-affecting <img> have numeric width and height attributes?
  • Do those values match the actual file or the selected art-directed crop?
  • Does responsive CSS use max-width: 100%; height: auto; where the complete image should remain visible?
  • Does each fixed-ratio component declare aspect-ratio?
  • Is object-fit: cover or contain intentional when the box and source ratios differ?
  • Do <picture> sources reserve the ratio of the crop selected at each breakpoint?
  • Are JavaScript-inserted images sized before they enter the document?
  • Are video, ads, embeds, font swaps, and late API content reserving space too?
  • Have you observed a cold-cache, throttled load rather than only a cached desktop refresh?
  • Have you checked both Lighthouse and field CLS when production behavior differs from the lab?

What success looks like

Before the image request completes, the page should already have a stable box with the intended ratio. As the file arrives, the image should paint inside that box without pushing neighboring text or controls. Responsive resizing should change the box dimensions proportionally, and intentional crops should remain visually consistent across breakpoints. If content still moves, the next investigation should target another dynamic element or a ratio mismatch rather than removing responsive behavior.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.