Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
CSS

How to Set PNG Image Size in HTML (Without Distortion)

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

Set a PNG’s displayed size with the <img> element’s width and height attributes, CSS, or both. Use the file’s intrinsic pixel dimensions in the attributes, then use max-width: 100%; height: auto when the image must shrink responsively without stretching. For a deliberately fixed frame, add object-fit: contain or cover according to whether cropping is acceptable.

Choose the sizing method that matches the job

Requirement Recommended implementation What happens
Natural image size with stable layout width and height attributes set to the PNG’s intrinsic dimensions The browser displays the image at its natural size and can reserve its aspect-ratio space before the file finishes loading.
Fluid image that can shrink on phones Intrinsic HTML dimensions plus max-width: 100%; height: auto The image never exceeds its container and keeps its original proportions.
Fixed thumbnail or card frame CSS width and height with object-fit contain shows everything with possible empty space; cover fills the box and may crop.
Different files for different displays srcset/sizes or <picture> The browser can select an appropriate source instead of downloading one oversized PNG everywhere.

Set PNG dimensions with HTML attributes

Put integer pixel values, without units, on the image element:

<img src="picture.png" alt="A mountain at sunrise" width="1200" height="800">

Replace 1200 and 800 with the PNG’s actual intrinsic width and height. These attributes describe the image’s intended dimensions; they are not written as 1200px. Supplying both values also gives the browser the aspect ratio early, so it can reserve layout space before the image is decoded. MDN Web Docs notes that including height and width enables this calculation before loading completes.

How to find the intrinsic size

  • Open the PNG in an image editor and read its pixel dimensions.
  • In a desktop file manager, open the file’s properties or information panel.
  • Inspect the image in browser developer tools; the natural dimensions are shown separately from rendered dimensions.

Do not confuse the source dimensions with the size you want on screen. A 2,400 × 1,600 PNG may be rendered at 600 × 400 CSS pixels while retaining its 3:2 ratio.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Make a PNG responsive without stretching

Keep the intrinsic attributes for layout stability and let CSS reduce the rendered width when the containing block is narrower:

<img class="responsive-png" src="picture.png" alt="A mountain at sunrise" width="1200" height="800">
.responsive-png {
  max-width: 100%;
  height: auto;
  display: block;
}

max-width: 100% prevents overflow. height: auto recalculates the displayed height from the intrinsic aspect ratio, preventing distortion. The optional display: block removes the small inline baseline gap that can appear beneath images.

Constrain the parent when needed

.article-column {
  width: min(100%, 720px);
  margin-inline: auto;
}
.article-column img {
  max-width: 100%;
  height: auto;
}

The image can still render below its intrinsic size, but it will not grow beyond the column. If you set a CSS width directly, use a proportional height:

.hero-png {
  width: 50%;
  height: auto;
}

Build a fixed image box with contain or cover

Sometimes every card must be exactly the same size even when source PNGs have different proportions. In that case, define the frame in CSS and choose how the replaced content fits:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
<img class="thumbnail" src="picture.png" alt="Product package">
.thumbnail {
  width: 320px;
  height: 200px;
  object-fit: contain;
  object-position: center;
}

Use object-fit: contain when all pixels matter

contain scales the complete PNG until it fits inside the 320 × 200 box. If the aspect ratios differ, unused space remains on two sides. This is appropriate for logos, screenshots, diagrams, and product artwork that must not be clipped.

Use object-fit: cover when the frame must be full

.thumbnail {
  width: 320px;
  height: 200px;
  object-fit: cover;
  object-position: 50% 30%;
}

cover fills the entire box, so a differently proportioned PNG is cropped. Set object-position to keep a subject near the visible area; percentages, lengths, and keywords such as top or right are useful for art direction. Do not use cover for text inside an image unless cropping is acceptable.

Use responsive image sources when one PNG is not enough

CSS resizing changes display size but does not change which file is downloaded. For bandwidth-sensitive pages, provide width variants and let the browser choose:

<img
  src="photo-1200.png"
  srcset="photo-480.png 480w, photo-800.png 800w, photo-1200.png 1200w"
  sizes="(max-width: 600px) 100vw, 720px"
  width="1200"
  height="800"
  alt="A mountain at sunrise">

The width descriptors tell the browser each candidate’s intrinsic width. sizes describes the slot width; here it is the viewport width up to 600 pixels and 720 CSS pixels on wider screens. Keep the width and height attributes in the same aspect ratio as the selected files so layout reservation remains correct.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Use <picture> for art direction

<picture>
  <source media="(max-width: 600px)" srcset="portrait.png">
  <img src="landscape.png" alt="City skyline" width="1600" height="900">
</picture>

Use this when mobile and desktop need genuinely different compositions, not merely different sizes. The fallback <img> remains required for browsers and accessibility.

Common mistakes and fixes

The image is stretched

Unequal width and height values, or CSS that sets both dimensions independently, changes the aspect ratio. Use the source ratio, set one dimension to auto, or use object-fit inside an intentional fixed frame.

The image overflows its container

Add max-width: 100%. Check for a parent with a fixed width, flex item minimum size, or CSS rule with greater specificity overriding your image rule.

Layout jumps while the PNG loads

Add accurate width and height attributes. If the values are wrong, the reserved space will also be wrong, so correct the metadata rather than hiding the image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Transparent areas show an unexpected color

PNG transparency reveals the element or page background. Set an explicit background on the wrapper when a checkerboard-like or colored result is not desired; resizing does not remove transparency.

The picture looks soft

A low-resolution source enlarged with CSS cannot create detail. Supply a larger source or a suitable srcset candidate. Conversely, downloading a very large PNG for a small slot wastes bandwidth.

object-fit appears to do nothing

It affects how replaced content fits inside a defined content box. Give the image both a CSS width and height (or place it in a box with those dimensions); with only one dimension and height: auto, there may be no alternate box to fit.

Inspect the result in developer tools

  1. Right-click the image and choose Inspect.
  2. Check the rendered width and height in the Layout or Computed panel.
  3. Compare those values with the image’s natural dimensions.
  4. In the Styles panel, find the rule that supplies the final width, height, max-width, and object-fit; crossed-out declarations are being overridden.
  5. Resize the viewport and confirm that the rendered height changes proportionally when using the responsive pattern.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to obtain a PNG of a webpage rather than size an existing local asset, ScreenshotNeo returns a screenshot from one GET request. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response reports the result in X-Page-Verdict and X-Billed headers.

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

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo documentation for parameters. The service also provides an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper settings, custom CSS and JavaScript, click and wait actions, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

The Free plan includes 1,000 shots each month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan. Create a free ScreenshotNeo account.

Practical decision checklist

  • Know the PNG’s intrinsic pixel dimensions.
  • Put accurate unitless width and height attributes on content images.
  • Use max-width: 100%; height: auto for fluid scaling.
  • Use contain when cropping is unacceptable and cover when a filled frame matters more.
  • Use srcset, sizes, or picture when display conditions require different source files.
  • Inspect computed dimensions when a rule appears ineffective.

Frequently Asked Questions

Do PNG width and height attributes use CSS units?

No. HTML image dimension attributes are integer pixel values such as width=”800″. Put units such as px, %, or rem in CSS declarations instead.

Can CSS resize a PNG without changing the original file?

Yes. CSS changes the rendered size in the page; it does not rewrite the PNG on disk.

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

Should I omit width and height for a responsive image?

Usually no. Keep accurate intrinsic dimensions for aspect-ratio reservation, then use CSS to make the rendered width fluid.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.