Use an <img> element whose src points to the PNG: <img src="images/example.png" alt="A concise description of the image">. Keep the PNG as a separate file for most sites. If the image bytes must travel inside the HTML document, replace the path with a data:image/png;base64,... data URL.
The standard way: reference a PNG file
The HTML Standard says that when a page has one image resource, you embed it with the img element and its src attribute. A complete example is:
<img src="images/example.png" alt="A concise description of the image">
src is a URL, not necessarily a local file-system path. The browser requests that URL and draws the returned image. The img element is a void element, so it must not have an </img> closing tag.
Choose the correct relative path
A relative URL is resolved from the URL of the HTML document. If your files look like this:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
project/
index.html
images/
logo.png
then index.html should use images/logo.png:
<img src="images/logo.png" alt="Site logo">
If the HTML file is in pages/about/index.html while the image is in images/logo.png at the project root, use ../../images/logo.png. A leading slash, such as /images/logo.png, is resolved from the website’s origin and normally points at the server root. An absolute URL, such as https://example.com/images/logo.png, can point to another origin when that resource is publicly available.
Make sure the URL is actually served
Put the PNG in the directory exposed by your web server or static-site host. Opening an HTML file directly with a file:// URL can hide deployment and path mistakes; test through the same local development server or hosting setup that will serve the page. The URL is case-sensitive on many servers, so Logo.png and logo.png may be different files.
Write useful alternative text
The alt attribute is the text alternative for the image. Describe the image’s relevant meaning in the page’s context, not its filename. For example:
<img src="chart.png" alt="Line chart showing revenue increasing from January through June">
The MDN img reference recommends an empty value, alt="", for a purely decorative image:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute<img src="ornament.png" alt="">
An empty value tells assistive technology to skip decoration. Do not omit alt for a meaningful image, use the filename as a description, or rely on title as a replacement for alternative text.
Keep the image’s layout stable
If you know the intrinsic dimensions, add numeric width and height attributes:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
<img src="images/hero.png"
width="1200"
height="630"
alt="Product dashboard overview">
Declaring dimensions lets the browser reserve the image’s space while it loads. The values describe the image’s intrinsic pixel dimensions; CSS can still control its rendered size. A common responsive rule is:
img {
max-width: 100%;
height: auto;
}
This keeps a large PNG from overflowing a narrow container while preserving its aspect ratio.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Use responsive sources when one PNG is not enough
For different files at different viewport widths or pixel densities, use srcset and sizes:
<img
src="images/photo-800.png"
srcset="images/photo-400.png 400w,
images/photo-800.png 800w,
images/photo-1600.png 1600w"
sizes="(max-width: 600px) 100vw, 800px"
alt="Mountain trail at sunrise">
The fallback src remains important. The browser uses the candidate list and the displayed-size hint to select an appropriate resource. Use <picture> when you need art direction, such as a different crop on a small screen:
<picture>
<source media="(max-width: 600px)" srcset="images/trail-crop-small.png">
<img src="images/trail-wide.png" alt="Mountain trail at sunrise">
</picture>
These are refinements, not prerequisites. A single PNG still uses the first img example.
Inline the PNG with a base64 data URL
If you need a self-contained HTML document, put the encoded bytes in src:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
<img
src="data:image/png;base64,BASE64_ENCODED_IMAGE_DATA"
alt="A concise description of the image">
The MDN data URL reference defines the form as data:[<media-type>][;base64],<data>. In this case, image/png identifies the media type and ;base64 tells the browser to decode the following text as base64. Replace the illustrative token with the complete encoding of your actual PNG; the token itself is not an image.
Generate the actual base64 text
On systems with a standard base64 utility, encode the file and insert the result after the comma:
base64 -w 0 logo.png > logo.txt
Some platforms do not support -w 0; in that case, remove line breaks with your platform’s equivalent or use a small script. Python can create a complete data URL:
import base64
with open("logo.png", "rb") as image_file:
encoded = base64.b64encode(image_file.read()).decode("ascii")
html_src = "data:image/png;base64," + encoded
print(html_src)
Copying binary bytes directly into HTML without base64 encoding does not create a valid data URL.
External file or inline data: which should you choose?
| Approach | Markup example | Best fit | Trade-offs |
|---|---|---|---|
| Separate PNG URL | src="images/logo.png" |
Most website images, reused assets, and files that may be updated | Requires the PNG to be deployed and reachable at that URL; the document is easy to read and maintain |
| Base64 data URL | src="data:image/png;base64,..." |
A self-contained document or a small asset that must travel with the markup | Makes HTML substantially harder to read and edit because the encoded content is long; changing the image means regenerating the data |
Inline data is an alternative representation of the same bytes, not a way to avoid providing the bytes. It also does not make an image universally faster. Modern browsers treat data URLs as unique opaque origins, which matters if your design depends on origin-based security or browser isolation. For a normal page, the separate file is the maintainable default.
Common mistakes and fixes
The image icon appears, but the PNG does not
- Open the exact
srcURL in a browser. A 404 or another error means the path, filename, or deployment location is wrong. - Check capitalization and spelling. A server may distinguish
image.pngfromImage.PNG. - Recalculate the relative path from the HTML document’s URL, not from your editor’s project tree.
- Confirm the server returns the actual PNG rather than an HTML error page. A resource can have a
.pngname and still contain the wrong response.
The image is stretched or squashed
Do not set a width and height with a conflicting aspect ratio. Use the intrinsic ratio, set one dimension and let the other be automatic, or apply height: auto in CSS.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
The data URL shows broken characters
- Encode the file in binary mode, not as text.
- Use the exact prefix
data:image/png;base64,, including the comma. - Do not paste a filename, a base64 value for a different image type, or a value truncated by an editor.
- Keep the generated string on one logical URL; accidental quotation marks or whitespace in the value can invalidate it.
The image is visible but inaccessible
Add meaningful alt text, or use alt="" when the image is decorative. Text embedded inside a picture may need a longer explanation in surrounding content if the image conveys information that a short label cannot express.
A responsive image is not selecting the file you expected
Check that each srcset URL is valid and that every width descriptor has a numeric w. Ensure sizes describes the image’s actual layout width; otherwise the browser has insufficient information to choose among candidates.
Security and deployment considerations
Only use image URLs you intend to load. A data URL embeds content in the document, so treat generated HTML as untrusted if users can supply the image or markup. Do not concatenate untrusted strings into HTML without the appropriate escaping and sanitization for your application. For external URLs, consider whether your site’s content-security policy permits the image origin. These controls are separate from choosing PNG versus another image format.
When publishing, verify the final page over the same protocol and host that users will access. A local relative path can work in a development directory yet fail after a build moves files to a different public directory. Keep asset names and references synchronized in your build process.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If what you actually need is a fresh PNG of a web page to place in your HTML, ScreenshotNeo returns a screenshot from one GET request. It accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and whether the request was billed. You can save the response as a PNG and reference that file with the ordinary img method above.
See the ScreenshotNeo API documentation for parameters and options. A minimal cURL capture is:
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://stripe.com
-o shot.webp
Change the URL to the page you need and use the resulting image file in HTML:
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
<img src="shot.webp" alt="Screenshot of the Stripe homepage">
The same request in Python is:
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)
And in 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(`Screenshot failed: ${res.status}`);
const bytes = Buffer.from(await res.arrayBuffer());
require('fs').writeFileSync('shot.webp', bytes);
ScreenshotNeo also provides an MCP server for AI agents, including Claude, Cursor, and other MCP clients, with take_screenshot, get_page_info, and capture_pdf tools. Its options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets or custom viewports, retina scale, custom CSS and JavaScript, click and wait actions, request blocking, headers and cookies, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. PNG, JPEG, WebP, and PDF outputs are supported.
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to start with those 1,000 monthly screenshots.
Quick checklist
- Use
<img src="..." alt="...">for a normal PNG. - Resolve relative paths from the HTML document’s URL and verify the deployed file exists.
- Use meaningful
alttext, oralt=""for decoration. - Add correct
widthandheightwhen intrinsic dimensions are known. - Use
srcset,sizes, orpictureonly when responsive candidates or art direction are needed. - Use a complete
data:image/png;base64,URL only when self-containment justifies bulkier markup.
Frequently Asked Questions
Does an HTML image need a closing tag?
No. img is a void element, so write its attributes in the opening tag and do not add </img>.
Free tools Windows power users keep installed
One-click scans. No signup required.
Can I use a PNG as a CSS background instead?
Yes, a PNG can be referenced from background-image, but that is a styling background rather than a content image. Use img when the image needs alternative text or represents page content.
What should I do when an image is decorative but still occupies layout space?
Keep the image element with alt="" so assistive technology can ignore it, and retain its dimensions or CSS sizing to preserve the intended visual layout.
Quick Recap
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.

