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 DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
accessibility

How to Put a PNG in HTML (Correct Paths, Alt Text, Responsive Images, and Fixes)

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

Use an <img> element and point its src attribute to the PNG’s reachable path or URL:

<img src="images/photo.png" alt="A red kite flying over a field">

The img element is a void element, so it has no closing tag. The browser resolves a relative path from the page URL, downloads the PNG, and displays it. Use useful alternative text, verify the exact filename and capitalization, and add intrinsic dimensions when you know them.

The minimum PNG markup

A standalone PNG normally needs only img, src, and alt. The src value is an image URL; it can be relative to the current page or an absolute HTTP(S) URL. At least one of src or srcset is required by the HTML image element specification (MDN’s img reference).

<img src="images/photo.png" alt="A red kite flying over a field">

Do not write </img>. Because img is a void element, a closing tag is invalid and unnecessary.

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.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Point src at the right file

Paths are resolved from the URL of the HTML document, not from whatever folder your code editor happens to show. These common layouts illustrate the correct values:

Project layout or situation Markup
index.html beside logo.png <img src="logo.png" alt="Company logo">
index.html in the project root and PNG in a sibling images folder <img src="images/logo.png" alt="Company logo">
PNG in a parent directory of the page <img src="../logo.png" alt="Company logo">
PNG hosted on another site at a known address <img src="https://cdn.example.com/logo.png" alt="Company logo">

The slash direction matters: web URLs use forward slashes. A path such as C:UsersmeDesktoplogo.png points to your computer’s filesystem and is not a public website URL. Upload the file to the site (or another host) and use the URL that visitors can reach. MDN’s HTML images tutorial explains the same relative-versus-absolute URL rule.

Relative paths and the page URL

If the page is served at https://example.com/products/index.html, images/item.png resolves under /products/images/item.png. Moving the page to another directory can therefore break an otherwise unchanged image tag. A root-relative path such as /images/item.png starts at the website’s domain root, while an absolute URL includes the full scheme and hostname.

Check spelling and capitalization

On many web servers, Logo.png and logo.png are different files. Match the directory names, filename, extension, and capitalization exactly. Paste the final URL into a browser: if it does not load there, the img element cannot load it either.

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

Write useful alternative text and reserve space

Alternative text is read when the image cannot be seen and by people using assistive technology. Describe the image’s content or purpose in the surrounding context; do not use a filename or the generic phrase “image.”

<img src="team.png" alt="The support team gathered around a conference table">

For a purely decorative image that conveys no information not already present in nearby text, use an empty value so assistive technology skips it:

<img src="swirl.png" alt="">

When the intrinsic dimensions are known, include both width and height. The browser can reserve that rectangle before the PNG arrives, reducing layout movement. CSS still controls the rendered size.

<img src="hero.png" alt="Mountain trail at sunrise" width="1600" height="900">

For a fluid image that stays inside its container, a typical rule is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
img {
  max-width: 100%;
  height: auto;
}

Do not distort the aspect ratio by setting unrelated width and height values unless you intentionally want cropping or stretching.

Use responsive PNG candidates when one file is not enough

A single src works for a fixed image. If you have several resolutions, use srcset. With width descriptors, sizes tells the browser how wide the image will appear so it can choose an efficient candidate. The final img remains the fallback and supplies its alternative text.

<img
  src="photo-800.png"
  srcset="photo-400.png 400w, photo-800.png 800w, photo-1600.png 1600w"
  sizes="(max-width: 600px) 100vw, 800px"
  width="1600"
  height="900"
  alt="A red kite flying over a field"
>

Use the picture element when the source should change by media condition or format, such as a different crop on narrow screens or a modern format with a PNG fallback:

<picture>
  <source media="(max-width: 600px)" srcset="portrait-crop.png">
  <source type="image/webp" srcset="photo.webp">
  <img src="photo.png" alt="A red kite flying over a field" width="1600" height="900">
</picture>

Guidance on srcset, sizes, and picture is covered in MDN’s Using images in HTML and image format guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Need Use
One known PNG img src="..."
Same image at several widths img with srcset and (for width descriptors) sizes
Different crops, viewport conditions, or formats picture with one fallback img

A complete page you can copy

This example assumes index.html is next to an images folder containing logo.png and hero.png:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>PNG example</title>
  <style>
    img { max-width: 100%; height: auto; display: block; }
    .hero { max-width: 60rem; margin: 2rem auto; padding: 0 1rem; }
  </style>
</head>
<body>
  <header>
    <img src="images/logo.png" alt="Acme company logo" width="240" height="80">
  </header>
  <main class="hero">
    <h1>Explore the trail</h1>
    <img src="images/hero.png" alt="Mountain trail at sunrise" width="1600" height="900">
  </main>
</body>
</html>

Keep the paths relative to this file’s served URL. If your server publishes the page at a nested route, confirm that the browser requests the directory you intended.

When the PNG does not appear

Work through these checks in order:

  1. Inspect the request. Open browser developer tools, select the Network panel, reload the page, and find the PNG request. A 404 usually means the path or filename is wrong; a 403 indicates that the server is refusing access.
  2. Open the image URL directly. Copy the requested URL from the Network panel and open it in a new tab. Fix the server location or deployment if that URL is not reachable.
  3. Compare every character. Check folder names, capitalization, extension, and accidental spaces. Verify that the deployed file is actually included in the build output.
  4. Recalculate the relative path. Start at the page’s URL directory and walk through each folder. A page moved from / to /docs/ may need ../images/photo.png instead of images/photo.png.
  5. Remove an empty or accidental source. An empty src can trigger an unintended request. Ensure your template did not replace the URL with an empty variable.
  6. Check the file itself. A truncated or corrupted PNG, unsupported metadata, or a file that is not really a PNG despite its extension can fail to decode. Re-export or replace it and test the new URL.
  7. Check network and access controls. Confirm the user can reach the host, authentication is not required unexpectedly, and the server returns an image response rather than an HTML error page.

MDN lists empty sources, corrupted data, unsupported formats, and inaccessible resources among image-loading failure causes (img reference). The Network panel reveals the actual status code and requested URL faster than guessing in the markup.

Deployment and maintenance checklist

  • Put the PNG in the directory that your web server publishes.
  • Use a URL relative to the page, or a complete reachable absolute URL.
  • Match case and extension exactly.
  • Give informative images concise alt text; use alt="" for decoration.
  • Set intrinsic width and height when known.
  • Use srcset/sizes for multiple resolutions and picture for conditional sources.
  • Test the deployed URL, not only a local editor preview.
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 the PNG you need is a screenshot of a web page, ScreenshotNeo can return a PNG, JPEG, WebP, or PDF from one GET request. It accepts cookie and consent banners as a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.

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

Use the API documentation at screenshotneo.com/docs/ for the complete option set. The endpoint can capture a full page with lazy images loaded, one CSS-selected element, dark mode, any viewport or one of 12 device presets, retina scale, custom CSS or JavaScript, clicks before capture, hidden selectors, selector/delay/network-idle waits, blocked ads or resource types, custom headers/cookies/user agents/Authorization, timezone and geolocation, transparent backgrounds, resizing, a chosen cache TTL, signed links for public <img> tags, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, usage data, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.

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,
)
r.raise_for_status()
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}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

After saving the returned file in your site’s published image directory, reference it normally, for example <img src="shot.webp" alt="Stripe homepage screenshot">. Keep the access key on your server rather than exposing it in client-side page source. ScreenshotNeo has a free plan with 1,000 shots per month and no card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan. Create a free ScreenshotNeo account.

FAQ

Does an img tag store the PNG inside the HTML file?

No. It stores a reference in src; the browser requests the PNG separately. The HTML remains small, and the image must stay available at that URL for visitors.

Can I change the visual size without editing the PNG?

Yes. Set presentation dimensions with CSS or HTML attributes while preserving the image’s aspect ratio. The file’s intrinsic pixels do not change unless you create a new image.

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.

Why does a screenshot API response not always have a .png filename?

The response format is chosen by the request and can be PNG, JPEG, WebP, or PDF. Save it with the matching extension and reference that saved filename in your HTML.

Frequently Asked Questions

Does an img tag store the PNG inside the HTML file?

No. It stores a URL reference in src; the browser fetches the PNG separately.

Can I change the displayed size without editing the PNG?

Yes. Use CSS or width and height attributes while preserving the source image’s aspect ratio.

Why might a screenshot API response use a .webp filename instead of .png?

ScreenshotNeo can return PNG, JPEG, WebP, or PDF. Save the response with the format you requested and use that filename in your img element.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.