Use a native <button> when a PNG starts an action, and put the image inside it. Give icon-only buttons an accessible name, set type="button" when the control is not submitting a form, and keep a visible focus style. Use an <a> when the image navigates or represents a download. If the PNG must be generated from live HTML, render the element to a canvas, convert the canvas to PNG, and trigger the download from a separate semantic button.
Choose the element that matches the user’s intent
| Intent | Correct control | Why |
|---|---|---|
| Run JavaScript or change UI state | <button type="button"> |
A button is an action control with built-in keyboard and assistive-technology behavior. |
| Go to another URL | <a href="..."> |
An anchor communicates navigation and supports normal browser features such as opening in a new tab. |
| Download a PNG generated from HTML | A native button that creates the file, plus a real download link | Canvas is bitmap output, not a replacement for semantic HTML controls. |
Do not use href="#" or javascript:void(0) to imitate a button. Those values create link behavior that can move the page, add history entries, or confuse keyboard and screen-reader users.
Use a static PNG as an action button
Accessible icon-only example
<button type="button" aria-label="Open settings" id="settingsButton">
<img src="settings.png" alt="" width="24" height="24">
</button>
<script>
document.querySelector('#settingsButton').addEventListener('click', () => {
document.querySelector('#settingsPanel').hidden = false;
});
</script>
The button’s accessible name comes from aria-label; the empty alt marks the image as decorative so it is not announced twice. If the icon has visible text, put that text inside the button and omit the redundant label.
Style without removing keyboard feedback
.image-button {
display: inline-flex;
align-items: center;
justify-content: center;
padding: .5rem;
border: 1px solid #9aa4b2;
border-radius: .4rem;
background: #fff;
cursor: pointer;
}
.image-button:hover { background: #f1f5f9; }
.image-button:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 3px;
}
.image-button img { display: block; }
Do not disable the outline with outline: none unless you provide an equally visible replacement. Fixed width and height attributes also reduce layout shift while the PNG loads.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#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.
Use a PNG image as a navigation link
<a href="/settings" class="image-link">
<img src="settings.png" alt="Settings" width="24" height="24">
</a>
Here the image’s alternative text names the destination. If nearby visible text already names the link, use alt="" to avoid repetition. Keep a real URL in href; users should be able to copy it, open it in a new tab, and navigate with browser history.
Generate a PNG from an HTML element
A static image button and an HTML-to-PNG workflow solve different problems. Conversion is useful for exporting a card, chart, invoice, or preview assembled from live DOM and CSS. It is not needed merely to make a button clickable.
Install and capture with html2canvas
npm install html2canvas
import html2canvas from 'html2canvas';
const exportButton = document.querySelector('#exportButton');
const target = document.querySelector('#capture');
exportButton.addEventListener('click', async () => {
exportButton.disabled = true;
try {
const canvas = await html2canvas(target, {
backgroundColor: '#ffffff',
scale: Math.min(window.devicePixelRatio || 1, 2),
useCORS: true
});
const link = document.createElement('a');
link.download = 'capture.png';
link.href = canvas.toDataURL('image/png');
link.click();
} catch (error) {
console.error('PNG export failed', error);
alert('The image could not be exported. Check external assets and try again.');
} finally {
exportButton.disabled = false;
}
});
The page markup can remain semantic:
<section id="capture" aria-labelledby="card-title">
<h2 id="card-title">Release summary</h2>
<p>Version 3.2 is ready for review.</p>
</section>
<button type="button" id="exportButton">Download image</button>
The button remains a keyboard-operable HTML control. The generated canvas is only the file output.
Offer a real download control
Programmatically clicking a temporary anchor is convenient for a one-click export. For a workflow where users may inspect or retry the file, assign the data URL to a visible link instead:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →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.
const link = document.querySelector('#downloadLink');
const canvas = await html2canvas(document.querySelector('#capture'));
link.href = canvas.toDataURL('image/png');
link.download = 'capture.png';
link.hidden = false;
Use download to suggest the filename. Browser policy, cross-origin responses, and server headers can still affect whether a download occurs.
Control fidelity, size, and output format
Scale for sharpness
The scale option controls bitmap density. A value near the device pixel ratio produces sharper output on high-density displays but increases width, height, memory use, encoding time, and file size. Cap it for large captures and test the browsers and devices you support.
Set dimensions deliberately
Canvas has its own pixel dimensions. Resizing a finished canvas with CSS can make it look blurry or distorted; choose the capture dimensions first. Very large pages can exceed browser or mobile canvas limits, so capture smaller regions or split a long document into sections when necessary.
Background and transparency
Set backgroundColor explicitly when a transparent page would produce an unexpected result. If transparency is required, use a transparent setting supported by your renderer and verify the result in an image viewer that displays alpha correctly.
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.
What html2canvas does not promise
html2canvas reconstructs a rendering from the DOM and CSS; it does not take a native browser screenshot. Unsupported CSS, pseudo-elements, fonts, filters, video, and complex layout effects may differ from what the user sees. Compare exported files with the live page for every style that matters.
Handle images, fonts, and cross-origin content
Images loaded from another origin must permit cross-origin use for them to appear reliably in a readable canvas. Configure appropriate CORS response headers on resources you control, or use a trusted proxy. A client-side renderer cannot bypass browser content-security rules. Cross-origin iframes are similarly restricted: if your script cannot read the frame, it cannot reproduce that content in the canvas.
- Prefer same-origin assets for predictable exports.
- Wait until web fonts and critical images have loaded before calling the renderer.
- Do not proxy arbitrary third-party URLs; a proxy can create privacy and security risks.
- Use a placeholder or an explicit error when an asset is unavailable instead of silently delivering an incomplete PNG.
Keyboard, screen-reader, and touch checks
- Tab to the control and activate it with Enter and Space.
- Confirm that the spoken name describes the action, such as “Open settings,” not merely “image.”
- Ensure the hit area is large enough for touch and that hover is not the only state.
- Keep disabled state and progress feedback visible when an export is running.
- Test with zoom and high-contrast settings; do not encode essential text only in a bitmap.
Common failures and fixes
The image is visible but the click does nothing
Check that the listener is attached after the element exists, that an overlay is not covering it, and that a disabled ancestor or button is not blocking interaction. Use browser developer tools to inspect the event target.
The button submits a form unexpectedly
Buttons inside forms default to submit behavior. Add type="button", or use type="submit" only when submission is intended.
Recommended Free Tools
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 export is blank or missing images
Wait for assets, verify the selector returns the intended element, and inspect cross-origin response headers. A canvas can become unusable (“tainted”) when it contains resources that do not grant access; fix the resource policy rather than trying to bypass it.
Fonts or CSS look different
Capture after fonts finish loading, simplify unsupported effects, and compare at the target scale. A DOM renderer will not reproduce every browser feature exactly.
The browser freezes or crashes
Reduce the capture area or scale, avoid enormous shadow-heavy DOM trees, and export sections separately. Large canvases consume memory proportional to their pixel dimensions.
The downloaded file has the wrong name or type
Set link.download and use canvas.toDataURL('image/png'). If you need JPEG, use its MIME type and a quality value, accepting that transparency is lost.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →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.
Or skip the browser setup:
ScreenshotNeo returns a rendered website image or PDF through one request. It accepts cookie and 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, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server gives Claude, Cursor, and other MCP clients take_screenshot, get_page_info, and capture_pdf tools.
For a PNG, JPEG, or WebP screenshot:
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 documentation for all 63 options, including full-page lazy-image loading, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, custom CSS and JavaScript, click-before-capture, hidden selectors, selector/delay/network-idle waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen-TTL caching, signed image links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage data, and the OpenAPI specification.
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(`HTTP ${res.status}`);
require('fs').writeFileSync('shot.webp', Buffer.from(await res.arrayBuffer()));
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is included on every plan. Sign up for ScreenshotNeo free.
FAQ
Can I make a PNG itself a button?
HTML has no special “PNG button” element. Put the image inside a native button for actions or inside an anchor for navigation.
Should I put the accessible label on the image or button?
For an icon-only action, name the button and set the image’s alt to empty. For a navigation link, the image alternative should describe the destination unless visible link text already does.
Does converting HTML to PNG preserve interactivity?
No. A PNG is a static bitmap. Keep interactive controls in HTML and export only when a non-interactive image file is required.
When is a server-side screenshot preferable?
Use a server-side service when you need consistent rendering outside a user’s browser, automation, cleanup of overlays, batch jobs, webhooks, or captures that must not depend on client-side CORS access.
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.

