The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →To show a PNG on a webpage, reference the image in an HTML <img> element; the image stays a PNG file. For a self-contained HTML file, embed the PNG bytes in a Base64 data URL instead. Neither method turns the pixels into editable HTML shapes.
What “convert PNG to HTML” means
HTML describes a webpage; PNG is a raster image format. In the usual case, you do not convert the PNG itself. You tell the browser where the PNG is and how it should appear. The browser loads and displays the image as part of the page. The MDN guide to the HTML image element explains how <img> embeds an image and how src and alt are used.
If you want one portable HTML file that contains the image data, use a Base64 data URL. The file still contains PNG data; it is simply written inline as text. If your goal is editable vector artwork, that is a separate tracing or reconstruction task, not a normal image-to-HTML conversion.
Put a PNG in a webpage with an image file
This is the best default for a normal website: keep the PNG as a separate asset and point to it with src.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
<img src="images/example.png" alt="A red bicycle leaning against a brick wall" width="640" height="420">
For example, if your project files look like this, the relative path is resolved from the HTML file’s location:
my-site/
├── index.html
└── images/
└── example.png
Place the <img> element in the page where the image belongs. Replace the sample path and description with your own. The width and height values should match the image’s intrinsic pixel dimensions or the dimensions you intend the browser to use; set them proportionally to avoid distortion. Providing dimensions lets the browser reserve the image’s aspect ratio while it loads, helping prevent surrounding content from jumping.
Write useful alternative text
- If the image communicates information, describe its relevant content concisely in
alt. - If it is purely decorative or repeats information already given in nearby text, use
alt="". - Do not use
titleas a replacement foralt; they serve different purposes.
The image element needs an image resource supplied through src or srcset. For a simple page, src is usually enough. The MDN reference covers the element’s attributes and image semantics.
Rank #2
Use the right path
A relative path such as images/example.png works when the PNG is stored within your project at that location. An absolute URL can point to an image hosted elsewhere. Check spelling, capitalization, file extension, and folder location if the browser shows a broken-image icon. A path that works from one HTML file may need to change when that file is moved to a different folder.
Embed the PNG inside a single HTML file
When the HTML file must travel on its own—for example, as a self-contained demo or a small offline document—encode the PNG’s binary bytes as Base64 and use a data URL:
<img src="data:image/png;base64,PASTE_BASE64_DATA_HERE" alt="Describe the image">
The syntax has two essential parts: the media type and encoding declaration, followed by a comma and the encoded data. For PNG, the media type is image/png. The comma separates the data URL’s metadata from its payload. The MDN data URL reference describes this format.
Rank #3
- 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
- Read the PNG file as binary data, not as ordinary text.
- Encode those bytes as Base64 using a local tool or a programming language.
- Put the result after
data:image/png;base64,in the image’ssrcvalue. - Save the HTML and open it in a browser to check that the image renders.
Keep a data URL on one continuous value when inserting it into markup. Line breaks, a missing comma, a wrong media type, or encoding text rather than the PNG bytes can make it invalid. Base64 is text representing the original bytes; it does not make the image vector-based or editable.
When inline embedding is a poor fit
Embedding turns the image into a long string inside the document. That can make the HTML harder to read, edit, diff, and maintain. Large data URLs also create practical performance and URL-length concerns; MDN does not establish one universal size cutoff, so do not treat any single threshold as applying to every browser or use case. For a site with reusable or substantial images, a separate PNG asset is generally easier to manage. See MDN’s data URL notes for further details.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows 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 reinstallUse a PNG as a decorative CSS background
If the image is part of the page’s decoration rather than content that needs an accessible text alternative, CSS can set it as a background:
Rank #4
.hero {
background-image: url("images/example.png");
background-size: cover;
background-position: center;
}
Use a regular <img> for meaningful content such as a product photo, chart, or illustration that conveys information. A CSS background does not provide the same image semantics or alternative text as an HTML image element. A CSS url() can also contain a data URL if inline embedding is specifically needed.
Choose the method that fits the job
| Need | Method | Main trade-off |
|---|---|---|
| Display an image on a normal webpage | <img src="images/example.png" alt="…"> |
Keeps the image in its own asset file and supports image semantics and alternative text. |
| Make one HTML file that includes a small PNG | Base64 data URL in img src |
Self-contained, but adds a long encoded string to the markup. |
| Show decorative artwork behind or around content | CSS background-image |
Useful for styling, but not a substitute for a content image’s alternative text. |
| Export an image generated or edited in a canvas | toDataURL() for small output; toBlob() with an object URL for larger output |
A data URL holds the complete encoded image in a string; blob workflows avoid that large string. |
| Make suitable artwork scalable and editable as vector shapes | Rebuild or trace as SVG | Works for artwork expressible as drawing commands, not as a general way to turn photographs into vectors. |
Export a PNG from a canvas
If a browser canvas is where the image is created or changed, HTMLCanvasElement.toDataURL() returns an image data URL. If no supported format is specified, the result is PNG. For a small output that you need to place directly in an img element, for example:
const canvas = document.querySelector("canvas");
const image = document.querySelector("#preview");
image.src = canvas.toDataURL("image/png");
For larger output, MDN recommends toBlob() with URL.createObjectURL() rather than materializing the entire image as an in-memory string. Revoke the object URL when it is no longer needed:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
const canvas = document.querySelector("canvas");
const image = document.querySelector("#preview");
canvas.toBlob((blob) => {
if (!blob) {
console.error("Canvas export failed.");
return;
}
const objectUrl = URL.createObjectURL(blob);
image.src = objectUrl;
image.addEventListener("load", () => {
URL.revokeObjectURL(objectUrl);
}, { once: true });
}, "image/png");
The output is still an image resource; an object URL is a temporary way for the page to refer to the generated blob. Canvas export can throw a SecurityError if the canvas is not origin-clean—for example, if it includes an image from another site without suitable cross-origin access. MDN documents these behaviors in its canvas toDataURL() reference.
When SVG is the better target
SVG describes drawings with text-based commands such as shapes and paths, so it can scale smoothly and is often suitable for icons, diagrams, and simple illustrations. A PNG is a grid of pixels. Tracing a PNG may approximate its outlines, but it does not automatically recover the original editable shapes, and the result may be poor for photographs or detailed bitmap artwork. Putting a PNG inside an SVG file still leaves the image as bitmap content. The MDN image format guide explains the distinction between raster images and vector formats.
Or skip the browser setup
If your real task is capturing a webpage as an image or PDF, rather than placing an existing PNG into HTML, ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request can return a PNG, JPEG, WebP, or PDF. Here is a cURL example:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up free for ScreenshotNeo.
Troubleshoot a PNG that does not appear
- Broken-image icon: Check that the file exists at the path in
src, and verify capitalization, extension, and the HTML file’s location. - Data URL fails to render: Confirm the prefix is
data:image/png;base64,, including its comma, and that the payload is Base64-encoded PNG bytes. - Image is stretched or squashed: Make the displayed width and height match the PNG’s aspect ratio; do not force unrelated dimensions.
- Content shifts as the page loads: Provide intrinsic
widthandheightvalues so the browser can reserve the aspect ratio. - Canvas export throws
SecurityError: Check whether the canvas contains cross-origin images and whether those images were loaded with suitable CORS access. Without an origin-clean canvas, browser export is blocked. - Huge HTML file or slow editing: Move the PNG into a separate asset file instead of embedding its bytes as a long Base64 string.
Frequently Asked Questions
Does converting a PNG to HTML make the image editable?
No. Referencing or Base64-embedding it displays the PNG; the image remains raster pixels. Editable vector artwork requires suitable source artwork or a separate tracing or reconstruction process.
Can I use a PNG data URL without a separate image file?
Yes. A data URL places Base64-encoded PNG bytes directly in the HTML, making the document self-contained, though the image data remains encoded text.
Why should I use alt text for a PNG?
For meaningful images, alt text provides a textual replacement. For decorative images, use an empty alt value; a title attribute does not replace alt.
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.
Free tools Windows power users keep installed
One-click scans. No signup required.

